add contacts

This commit is contained in:
Peter Maquiran
2024-06-10 16:34:43 +01:00
parent 193e7474e9
commit bf1457417d
23 changed files with 348 additions and 481 deletions
@@ -7,6 +7,7 @@ import { Observable } from 'rxjs';
import { RoomOutPutDTO } from '../../dto/room/roomOutputDTO';
import { z } from 'zod';
import { MessageInputDTO } from '../../dto/message/messageInputDtO';
import { SessionStore } from 'src/app/store/session.service';
const tableSchema = z.object({
@@ -51,7 +52,6 @@ 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) {
@@ -65,7 +65,6 @@ 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) {
@@ -78,8 +77,6 @@ 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 {
@@ -87,8 +84,8 @@ export class MessageLocalDataSourceService {
}
}
getItemsLive(roomId: string): Observable<RoomListOutPutDTO> {
return liveQuery(() => messageDataSource.message.where('roomId').equals(roomId).toArray() as any) as any
getItemsLive(roomId: string) {
return liveQuery(() => messageDataSource.message.where('roomId').equals(roomId).toArray() )
}
@@ -1,10 +1,10 @@
import { Injectable } from '@angular/core';
import { HttpService } from 'src/app/services/http.service';
import { MessageListInputDTO } from '../../dto/message/messageListInputDTO';
import { DataSourceReturn } from '../../../type';
import { MessageInputDTO, MessageInputDTOSchema } from '../../dto/message/messageInputDtO';
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
import { MessageOutPutDTO } from '../../dto/message/messageOutputDTO';
import { APIReturn } from 'src/app/services/decorators/api-validate-schema.decorator';
import { MessageOutPutDTO, MessageOutPutDTOSchema } from '../../dto/message/messageOutputDTO';
import { MessageListOutput } from '../../dto/message/messageListOutputDTO';
@Injectable({
@@ -16,6 +16,7 @@ export class MessageRemoteDataSourceService {
constructor(private httpService: HttpService) {}
@APIReturn(MessageOutPutDTOSchema)
@ValidateSchema(MessageInputDTOSchema)
async sendMessage(data: MessageInputDTO) {
return await this.httpService.post<MessageOutPutDTO>(`${this.baseUrl}/Messages`, data);
@@ -3,13 +3,14 @@ import { Result } from 'neverthrow';
import { HttpService } from 'src/app/services/http.service';
import { RoomListOutPutDTO, RoomListOutPutDTOSchema } from '../../dto/room/roomListOutputDTO';
import { RoomInputDTO, RoomInputDTOSchema } from '../../dto/room/roomInputDTO';
import { RoomOutPutDTO } from '../../dto/room/roomOutputDTO';
import { RoomOutPutDTO, RoomOutPutDTOSchema } from '../../dto/room/roomOutputDTO';
import { AddMemberToRoomInputDTO, AddMemberToRoomInputDTOSchema } from '../../dto/room/addMemberToRoomInputDto';
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
import { DataSourceReturn } from '../../../type';
import { RoomByIdInputDTO, RoomByIdInputDTOSchema } from '../../dto/room/roomByIdInputDTO';
import { RoomByIdOutputDTO, RoomByIdOutputDTOSchema } from '../../dto/room/roomByIdOutputDTO';
import { APIReturn } from 'src/app/services/decorators/api-validate-schema.decorator';
import { UserRemoveListInputDTO, UserRemoveListInputDTOSchema } from '../../dto/room/userRemoveListInputDTO';
@Injectable({
providedIn: 'root'
@@ -22,6 +23,7 @@ export class RoomRemoteDataSourceService {
@ValidateSchema(RoomInputDTOSchema)
@APIReturn(RoomOutPutDTOSchema)
async createRoom(data: RoomInputDTO): DataSourceReturn<RoomOutPutDTO> {
return await this.httpService.post<RoomOutPutDTO>(`${this.baseUrl}/Room`, data);
}
@@ -43,16 +45,18 @@ export class RoomRemoteDataSourceService {
}
async deleteRoom(id: string): Promise<Result<any ,any>> {
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${id}`);
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${id}`, {});
}
@ValidateSchema(AddMemberToRoomInputDTOSchema)
async addMemberToRoom(data: AddMemberToRoomInputDTO): DataSourceReturn<AddMemberToRoomInputDTO> {
return await this.httpService.post<any>(`${this.baseUrl}/Room/${data.id}/Member`, data.member);
return await this.httpService.post<any>(`${this.baseUrl}/Room/${data.id}/Member`, { members:data.members });
}
async removeMemberFromRoom(id: string, member: any): Promise<Result<any ,any>> {
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${id}/Member`);
@ValidateSchema(UserRemoveListInputDTOSchema)
async removeMemberFromRoom(data: UserRemoveListInputDTO): Promise<Result<any ,any>> {
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${data.id}/Member`, {members:data.members});
}
}
@@ -1,8 +1,7 @@
import { Injectable } from '@angular/core';
import { RoomListItemOutPutDTO, RoomListOutPutDTO } from '../../dto/room/roomListOutputDTO';
import { Dexie, EntityTable, liveQuery } from 'Dexie';
import { Dexie, EntityTable, liveQuery, Observable } from 'Dexie';
import { err, ok } from 'neverthrow';
import { Observable } from 'rxjs';
import { z } from 'zod';
import { UserList } from '../../../contacts/data-source/contacts-data-source.service';
@@ -114,8 +113,11 @@ export class RoomLocalDataSourceService {
return liveQuery(() => roomDataSource.room.get(id)) as any;
}
getRoomMemberByIdLive(roomId: any): Observable<TableMemberList[] | undefined> {
return liveQuery(() => roomDataSource.memberList.where('roomId').equals(roomId).toArray()) as any;
async getRoomMemberById(roomId: any) {
return await roomDataSource.memberList.where('roomId').equals(roomId).toArray()
}
getRoomMemberByIdLive(roomId: any) {
return liveQuery(() => roomDataSource.memberList.where('roomId').equals(roomId).toArray())
}
}
@@ -4,10 +4,15 @@ const DataSchema = z.object({
id: z.string(),
chatRoomId: z.string(),
wxUserId: z.number(),
sender: z.string().nullable(),
sender: z.object({
wxUserId: z.number(),
wxFullName: z.string(),
wxeMail: z.string(),
userPhoto: z.string().optional()
}).nullable(),
message: z.string(),
messageType: z.number(),
sentAt: z.string().datetime(),
sentAt: z.string(),
deliverAt: z.string().datetime().nullable(),
canEdit: z.boolean(),
oneShot: z.boolean(),
@@ -15,10 +20,10 @@ const DataSchema = z.object({
});
const ResponseSchema = z.object({
export const MessageOutPutDTOSchema = z.object({
success: z.boolean(),
message: z.string(),
data: DataSchema
});
export type MessageOutPutDTO = z.infer<typeof ResponseSchema>
export type MessageOutPutDTO = z.infer<typeof MessageOutPutDTOSchema>
@@ -2,7 +2,7 @@ import { z } from "zod";
export const AddMemberToRoomInputDTOSchema = z.object({
id: z.string(),
member: z.string(),
members: z.array(z.number()),
});
export type AddMemberToRoomInputDTO = z.infer<typeof AddMemberToRoomInputDTOSchema>
@@ -1,6 +1,6 @@
import { z } from "zod";
const RoomOutPutDTOSchema = z.object({
export const RoomOutPutDTOSchema = z.object({
success: z.string(),
message: z.string(),
data: z.object({
@@ -0,0 +1,9 @@
import { z } from "zod";
// Define the schema for the entire response
export const UserRemoveListInputDTOSchema = z.object({
id: z.string(),
members: z.array(z.number())
});
export type UserRemoveListInputDTO = z.infer<typeof UserRemoveListInputDTOSchema>
@@ -4,6 +4,7 @@ import { MessageLiveDataSourceService } from '../data-source/message/message-liv
import { MessageListInputDTO } from '../dto/message/messageListInputDTO';
import { MessageInputDTO } from '../dto/message/messageInputDtO';
import { MessageLocalDataSourceService, TableMessage } from '../data-source/message/message-local-data-source.service';
import { SessionStore } from 'src/app/store/session.service';
@Injectable({
providedIn: 'root'
@@ -18,6 +19,13 @@ export class MessageRepositoryService {
async sendMessage(data: MessageInputDTO) {
(data as TableMessage).sender = {
userPhoto: '',
wxeMail: SessionStore.user.Email,
wxFullName: SessionStore.user.FullName,
wxUserId: SessionStore.user.UserId
}
const localActionResult = await this.messageLocalDataSourceService.createMessage(data)
if(localActionResult.isOk()) {
@@ -25,14 +33,12 @@ export class MessageRepositoryService {
if(sendMessageResult.isOk()) {
if(sendMessageResult.value.data.sender == null) {
delete sendMessageResult.value.data.sender
}
let clone: TableMessage = {
...sendMessageResult.value.data,
sender: {
userPhoto: '',
wxeMail: '',
wxFullName: '',
wxUserId: 0
},
messageId: sendMessageResult.value.data.id,
id : localActionResult.value
}
@@ -7,7 +7,7 @@ import { AddMemberToRoomInputDTO } from '../dto/room/addMemberToRoomInputDto';
import { RoomLocalDataSourceService } from '../data-source/room/rooom-local-data-source.service';
import { RoomByIdInputDTO } from '../dto/room/roomByIdInputDTO';
import { roomListDetermineChanges } from '../async/rooms/roomListChangeDetector';
import { value } from '../../../../../plugin/src/sql/Operators/args-attributes';
import { UserRemoveListInputDTO } from '../dto/room/userRemoveListInputDTO';
@Injectable({
providedIn: 'root'
@@ -50,6 +50,8 @@ export class RoomRepositoryService {
}
}
return result
}
async create(data: RoomInputDTO) {
@@ -71,6 +73,13 @@ export class RoomRepositoryService {
return result
}
async removeMemberToRoom(data: UserRemoveListInputDTO) {
const result = await this.roomRemoteDataSourceService.removeMemberFromRoom(data)
return result
}
getItemsLive() {
return this.roomLocalDataSourceService.getItemsLive()
}
@@ -83,4 +92,8 @@ export class RoomRepositoryService {
getRoomMemberByIdLive(roomId: any) {
return this.roomLocalDataSourceService.getRoomMemberByIdLive(roomId)
}
getRoomMemberById(roomId: any) {
return this.roomLocalDataSourceService.getRoomMemberById(roomId)
}
}