mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
show rooms
This commit is contained in:
+63
@@ -0,0 +1,63 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AddMemberToRoomInputDTO } from '../../dto/room/addMemberToRoomInputDto';
|
||||
import { RoomListOutPutDTO } from '../../dto/room/roomListOutputDTO';
|
||||
import { Dexie, EntityTable, liveQuery } from 'Dexie';
|
||||
import { err, ok } from 'neverthrow';
|
||||
import { Observable } from 'rxjs';
|
||||
import { RoomOutPutDTO } from '../../dto/room/roomOutputDTO';
|
||||
import { z } from 'zod';
|
||||
import { MessageInputDTO } from '../../dto/message/messageInputDtO';
|
||||
|
||||
|
||||
const tableSchema = z.object({
|
||||
id: z.any().optional(),
|
||||
roomId: z.string().uuid(),
|
||||
senderId: z.number(),
|
||||
message: z.string(),
|
||||
messageType: z.number(),
|
||||
canEdit: z.boolean(),
|
||||
oneShot: z.boolean(),
|
||||
requireUnlock: z.boolean(),
|
||||
})
|
||||
|
||||
export type TableMessage = z.infer<typeof tableSchema>
|
||||
|
||||
// Database declaration (move this to its own module also)
|
||||
export const messageDataSource = new Dexie('chat-message') as Dexie & {
|
||||
message: EntityTable<TableMessage, 'id'>;
|
||||
};
|
||||
|
||||
messageDataSource.version(1).stores({
|
||||
message: '++id, roomId, senderId, message, messageType, canEdit, oneShot, requireUnlock'
|
||||
});
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MessageLocalDataSourceService {
|
||||
|
||||
private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2/Chat'; // Your base URL
|
||||
|
||||
constructor() {}
|
||||
|
||||
|
||||
async createMessage(data: MessageInputDTO) {
|
||||
|
||||
try {
|
||||
const result = await messageDataSource.message.add(data)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getItemsLive(): Observable<RoomListOutPutDTO[]> {
|
||||
return liveQuery(() => messageDataSource.message.toArray()) as any;
|
||||
}
|
||||
|
||||
|
||||
addIdToMessage() {}
|
||||
|
||||
}
|
||||
|
||||
+6
-4
@@ -1,9 +1,10 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpService } from 'src/app/services/http.service';
|
||||
import { MessageOutPutDTO } from '../../dto/message/messageOutputDTO';
|
||||
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';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -14,8 +15,9 @@ export class MessageRemoteDataSourceService {
|
||||
|
||||
constructor(private httpService: HttpService) {}
|
||||
|
||||
async sendMessage(message: any) {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Messages`, message);
|
||||
@ValidateSchema(MessageInputDTOSchema)
|
||||
async sendMessage(data: MessageInputDTO) {
|
||||
return await this.httpService.post<MessageOutPutDTO>(`${this.baseUrl}/Messages`, data);
|
||||
}
|
||||
|
||||
async reactToMessage(id: string, reaction: any) {
|
||||
|
||||
+5
-25
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AddMemberToRoomInputDTO } from '../../dto/room/addMemberToRoomInputDto';
|
||||
import { RoomListOutPutDTO } from '../../dto/room/roomListOutputDTO';
|
||||
import { RoomListItemOutPutDTO, RoomListOutPutDTO } from '../../dto/room/roomListOutputDTO';
|
||||
import { Dexie, EntityTable, liveQuery } from 'Dexie';
|
||||
import { err, ok } from 'neverthrow';
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -49,33 +49,13 @@ export class RoomLocalDataSourceService {
|
||||
|
||||
}
|
||||
|
||||
async getRoomList() {
|
||||
|
||||
}
|
||||
|
||||
async getRoom(id: string){
|
||||
|
||||
}
|
||||
|
||||
async updateRoom(id: string, room: any) {
|
||||
|
||||
}
|
||||
|
||||
async deleteRoom(id: string){
|
||||
|
||||
}
|
||||
|
||||
async addMemberToRoom(data: AddMemberToRoomInputDTO) {
|
||||
|
||||
}
|
||||
|
||||
async removeMemberFromRoom(id: string, member: any){
|
||||
|
||||
}
|
||||
|
||||
getItemsLive(): Observable<RoomListOutPutDTO[]> {
|
||||
return liveQuery(() => roomDataSource.room.toArray()) as any;
|
||||
}
|
||||
|
||||
getRoomByIdLive(id: any): Observable<RoomListItemOutPutDTO | undefined> {
|
||||
return liveQuery(() => roomDataSource.room.get(id)) as any;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const MessageInputDTOSchema = z.object({
|
||||
roomId: z.string().uuid(),
|
||||
senderId: z.number(),
|
||||
message: z.string(),
|
||||
messageType: z.number(),
|
||||
canEdit: z.boolean(),
|
||||
oneShot: z.boolean(),
|
||||
requireUnlock: z.boolean(),
|
||||
});
|
||||
|
||||
|
||||
export type MessageInputDTO = z.infer<typeof MessageInputDTOSchema>
|
||||
@@ -1,20 +1,9 @@
|
||||
import { z } from "zod"
|
||||
|
||||
const MessageOutPutDTOSchema = z.object({
|
||||
id: z.string(),
|
||||
sender: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string().email(),
|
||||
userPhoto: z.string()
|
||||
}),
|
||||
message: z.string().datetime(),
|
||||
messageType: z.string().datetime(),
|
||||
sentAt: z.number(),
|
||||
deliverAt: z.any(),
|
||||
canEdit: z.any(),
|
||||
oneShot: z.any(),
|
||||
requireUnlock: z.any()
|
||||
success: z.boolean(),
|
||||
message: z.string(),
|
||||
data: z.any()
|
||||
});
|
||||
|
||||
export type MessageOutPutDTO = z.infer<typeof MessageOutPutDTOSchema>
|
||||
|
||||
@@ -2,6 +2,8 @@ import { Injectable } from '@angular/core';
|
||||
import { MessageRemoteDataSourceService } from '../data-source/message/message-remote-data-source.service';
|
||||
import { MessageLiveDataSourceService } from '../data-source/message/message-live-data-source.service';
|
||||
import { MessageListInputDTO } from '../dto/message/messageListInputDTO';
|
||||
import { MessageInputDTO } from '../dto/message/messageInputDtO';
|
||||
import { MessageLocalDataSourceService } from '../data-source/message/message-local-data-source.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -10,11 +12,17 @@ export class MessageRepositoryService {
|
||||
|
||||
constructor(
|
||||
private messageRemoteDataSourceService: MessageRemoteDataSourceService,
|
||||
private messageLiveDataSourceService: MessageLiveDataSourceService
|
||||
private messageLiveDataSourceService: MessageLiveDataSourceService,
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService
|
||||
) {}
|
||||
|
||||
async sendMessage() {
|
||||
// const result = this.messageRemoteDataSourceService.sendMessage()
|
||||
async sendMessage(data: MessageInputDTO) {
|
||||
|
||||
const localActionResult = await this.messageLocalDataSourceService.createMessage(data)
|
||||
|
||||
if(localActionResult.isOk()) {
|
||||
const sendMessageResult = await this.messageRemoteDataSourceService.sendMessage(data)
|
||||
}
|
||||
}
|
||||
|
||||
async getMessagesFromRoom(data: MessageListInputDTO) {
|
||||
|
||||
@@ -5,6 +5,8 @@ import { addRoom, RoomRemoteDataSourceState } from '../data-source/room/room-mem
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AddMemberToRoomInputDTO } from '../dto/room/addMemberToRoomInputDto';
|
||||
import { RoomLocalDataSourceService } from '../data-source/room/rooom-local-data-source.service';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { ZodError } from 'zod';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -29,6 +31,8 @@ export class RoomRepositoryService {
|
||||
const result = await this.roomRemoteDataSourceService.createRoom(data)
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
console.log('result', result)
|
||||
this.roomMemoryDataSourceService.dispatch( addRoom(result.value) )
|
||||
|
||||
this.roomLocalDataSourceService.createRoom(result.value)
|
||||
@@ -47,4 +51,8 @@ export class RoomRepositoryService {
|
||||
getItemsLive() {
|
||||
return this.roomLocalDataSourceService.getItemsLive()
|
||||
}
|
||||
|
||||
getItemByIdLive(id: any) {
|
||||
return this.roomLocalDataSourceService.getRoomByIdLive(id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user