mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
add send message to chat
This commit is contained in:
+39
-1
@@ -19,6 +19,12 @@ const tableSchema = z.object({
|
||||
canEdit: z.boolean(),
|
||||
oneShot: z.boolean(),
|
||||
requireUnlock: z.boolean(),
|
||||
sender: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string()
|
||||
})
|
||||
})
|
||||
|
||||
export type TableMessage = z.infer<typeof tableSchema>
|
||||
@@ -45,9 +51,11 @@ export class MessageLocalDataSourceService {
|
||||
async createMessage(data: MessageInputDTO) {
|
||||
|
||||
try {
|
||||
console.log('add', data)
|
||||
const result = await messageDataSource.message.add(data)
|
||||
return ok(result as string)
|
||||
} catch (e) {
|
||||
console.log('add error')
|
||||
return err(false)
|
||||
}
|
||||
|
||||
@@ -57,6 +65,7 @@ export class MessageLocalDataSourceService {
|
||||
async update(data: TableMessage) {
|
||||
|
||||
try {
|
||||
console.log('update', data)
|
||||
const result = await messageDataSource.message.update(data.id, data)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
@@ -65,12 +74,41 @@ export class MessageLocalDataSourceService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
async findOrUpdate(data: TableMessage) {
|
||||
const findResult = await this.findMessageById(data.messageId)
|
||||
|
||||
console.log('findOrUpdate', findResult)
|
||||
|
||||
if(findResult.isOk()) {
|
||||
return this.update({...findResult.value, ...data})
|
||||
} else {
|
||||
return this.createMessage(data)
|
||||
}
|
||||
}
|
||||
|
||||
getItemsLive(roomId: string): Observable<RoomListOutPutDTO> {
|
||||
return liveQuery(() => messageDataSource.message.where('roomId').equals(roomId).toArray() as any) as any
|
||||
}
|
||||
|
||||
|
||||
addIdToMessage() {}
|
||||
async findMessageById(messageId: string) {
|
||||
try {
|
||||
console.log('messageId', messageId)
|
||||
const a = await messageDataSource.message.where('messageId').equals(messageId).first()
|
||||
|
||||
if(a) {
|
||||
return ok(a)
|
||||
} else {
|
||||
return err('not found')
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.log('error')
|
||||
return err('DB error')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user