Open abdulragib opened 1 month ago
import {Model} from '@nozbe/watermelondb'; import {date, field, json} from '@nozbe/watermelondb/decorators';
export default class IndividualChatModel extends Model { static table = 'individualChat';
@field('chat_id') chat_id; @field('chat') chat; @json('members', json => json) members; // JSON to store member IDs @field('last_message') last_message; @field('last_message_timestamp') last_message_timestamp; @json('clear_chat_date', json => json) clear_chat_date; @json('unread_count', json => json) unread_count; // JSON to store unread counts @field('is_blocked') is_blocked; @json('blockers', json => json) blockers; // JSON to store blockers @json('muted', json => json) muted; // JSON to store mute status @json('reports', json => json) reports; // JSON to store reports @json('calls', json => json) calls; // JSON to store call IDs @field('deleted') deleted; @date('created_at') created_at; @date('updated_at') updated_at; }
when read the data , i got wrong json format , [{"_changed": "", "_status": "created", "blockers": "", "calls": "{newValue={is_group_call=false, recording_url=null, individual_chat_id=66f828963bf7e7fb763b3825, initiator=66e9e8035ac4685afc715c64, end_time=2024-09-28T16:05:26.425Z, call_id=call_66e9e3f75ac4685afc715c57_1727539526393, duration=00:02:50, start_time=2024-09-28T16:02:40.183Z, createdAt=2024-09-28T16:05:31.814Z, is_individual_call=true, v=0.0, _id=66f8294b3bf7e7fb763b383c, call_type=Audio, status=cancelled, participants=[66e9e8035ac4685afc715c64, 66e9e3f75ac4685afc715c57], updatedAt=2024-09-28T16:05:31.814Z}, is_group_call=false, recording_url=null, individual_chat_id=66f828963bf7e7fb763b3825, initiator=66e9e8035ac4685afc715c64, end_time=2024-09-28T16:02:38.095Z, call_id=call_66e9e3f75ac4685afc715c57_1727539358041, duration=00:00:05, createdAt=2024-09-28T16:02:46.454Z, start_time=null, is_individual_call=true, v=0.0, _id=66f828a63bf7e7fb763b3832, call_type=Audio, updatedAt=2024-09-28T16:02:46.454Z, participants=[66e9e8035ac4685afc715c64, 66e9e3f75ac4685afc715c57], status=cancelled}", "chat": "individual", "chat_id": "66f828963bf7e7fb763b3825", "clear_chat_date": [], "created_at": 1727539350889, "deleted": false, "id": "QKm05GPsEeavjCg2", "is_blocked": false, "last_message": "", "last_message_timestamp": "", "members": [[Object], [Object]], "muted": {}, "reports": "", "unread_count": {}, "updated_at": 0}]
json field used to automaic stored as string , those fields are array so i declare as string but when i fetch it it showing as string , how to fix it
import {Model} from '@nozbe/watermelondb'; import {date, field, json} from '@nozbe/watermelondb/decorators';
export default class IndividualChatModel extends Model { static table = 'individualChat';
@field('chat_id') chat_id; @field('chat') chat; @json('members', json => json) members; // JSON to store member IDs @field('last_message') last_message; @field('last_message_timestamp') last_message_timestamp; @json('clear_chat_date', json => json) clear_chat_date; @json('unread_count', json => json) unread_count; // JSON to store unread counts @field('is_blocked') is_blocked; @json('blockers', json => json) blockers; // JSON to store blockers @json('muted', json => json) muted; // JSON to store mute status @json('reports', json => json) reports; // JSON to store reports @json('calls', json => json) calls; // JSON to store call IDs @field('deleted') deleted; @date('created_at') created_at; @date('updated_at') updated_at; }
when read the data , i got wrong json format , [{"_changed": "", "_status": "created", "blockers": "", "calls": "{newValue={is_group_call=false, recording_url=null, individual_chat_id=66f828963bf7e7fb763b3825, initiator=66e9e8035ac4685afc715c64, end_time=2024-09-28T16:05:26.425Z, call_id=call_66e9e3f75ac4685afc715c57_1727539526393, duration=00:02:50, start_time=2024-09-28T16:02:40.183Z, createdAt=2024-09-28T16:05:31.814Z, is_individual_call=true, v=0.0, _id=66f8294b3bf7e7fb763b383c, call_type=Audio, status=cancelled, participants=[66e9e8035ac4685afc715c64, 66e9e3f75ac4685afc715c57], updatedAt=2024-09-28T16:05:31.814Z}, is_group_call=false, recording_url=null, individual_chat_id=66f828963bf7e7fb763b3825, initiator=66e9e8035ac4685afc715c64, end_time=2024-09-28T16:02:38.095Z, call_id=call_66e9e3f75ac4685afc715c57_1727539358041, duration=00:00:05, createdAt=2024-09-28T16:02:46.454Z, start_time=null, is_individual_call=true, v=0.0, _id=66f828a63bf7e7fb763b3832, call_type=Audio, updatedAt=2024-09-28T16:02:46.454Z, participants=[66e9e8035ac4685afc715c64, 66e9e3f75ac4685afc715c57], status=cancelled}", "chat": "individual", "chat_id": "66f828963bf7e7fb763b3825", "clear_chat_date": [], "created_at": 1727539350889, "deleted": false, "id": "QKm05GPsEeavjCg2", "is_blocked": false, "last_message": "", "last_message_timestamp": "", "members": [[Object], [Object]], "muted": {}, "reports": "", "unread_count": {}, "updated_at": 0}]
json field used to automaic stored as string , those fields are array so i declare as string but when i fetch it it showing as string , how to fix it