mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 13:26:08 +00:00
fix issues
This commit is contained in:
@@ -5,8 +5,19 @@ import { RoomByIdInputDTO, RoomByIdOutputDTO } from "src/app/core/chat/usecase/r
|
||||
import { RoomUpdateInputDTO, RoomUpdateOutputDTO } from "src/app/core/chat/usecase/room/room-update-by-id-use-case.service";
|
||||
import { Result } from "neverthrow";
|
||||
import { AddMemberToRoomInputDTO } from "src/app/core/chat/usecase/member/member-add-use-case.service";
|
||||
import { RoomListOutPutDTO } from "src/app/core/chat/usecase/room/room-get-list-use-case.service";
|
||||
import { RoomListItemOutPutDTO, RoomListItemSchema, RoomListOutPutDTO } from "src/app/core/chat/usecase/room/room-get-list-use-case.service";
|
||||
|
||||
|
||||
export interface ISearchRoom {
|
||||
|
||||
success: boolean,
|
||||
message: any,
|
||||
data: {
|
||||
messages: [],
|
||||
rooms: RoomListItemSchema[]
|
||||
}
|
||||
|
||||
}
|
||||
export abstract class IRoomRemoteRepository {
|
||||
abstract createRoom(data: CreateRoomInputDTO): DataSourceReturn<RoomOutPutDTO>
|
||||
abstract getRoomList(): Promise<DataSourceReturn<RoomListOutPutDTO>>
|
||||
@@ -14,4 +25,5 @@ export abstract class IRoomRemoteRepository {
|
||||
abstract updateRoom(data: RoomUpdateInputDTO): Promise<DataSourceReturn<RoomUpdateOutputDTO>>
|
||||
abstract deleteRoom(id: string): Promise<Result<any ,any>>
|
||||
abstract addMemberToRoomSocket(data: AddMemberToRoomInputDTO): Promise<Result<any ,any>>
|
||||
abstract search(input: string): Promise<Result<RoomListItemOutPutDTO[], any>>
|
||||
}
|
||||
|
||||
@@ -19,18 +19,20 @@ const CreatedBySchema = z.object({
|
||||
userPhoto: z.string().nullable()// api check
|
||||
});
|
||||
|
||||
const roomListItemSchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: CreatedBySchema,
|
||||
createdAt: z.string(),
|
||||
expirationDate: z.string().nullable(), // api check
|
||||
roomType: z.number(),
|
||||
messages: MessageEntitySchema.array(),
|
||||
user1: CreatedBySchema.nullable(),
|
||||
user2: CreatedBySchema.nullable()
|
||||
})
|
||||
|
||||
const RoomListItemOutPutDTOSchema = z.object({
|
||||
chatRoom: z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: CreatedBySchema,
|
||||
createdAt: z.string(),
|
||||
expirationDate: z.string().nullable(), // api check
|
||||
roomType: z.number(),
|
||||
messages: MessageEntitySchema.array(),
|
||||
user1: CreatedBySchema.nullable(),
|
||||
user2: CreatedBySchema.nullable()
|
||||
}),
|
||||
chatRoom: roomListItemSchema,
|
||||
joinAt: z.string()
|
||||
})
|
||||
|
||||
@@ -43,7 +45,7 @@ export const RoomListOutPutDTOSchema = z.object({
|
||||
});
|
||||
|
||||
export type RoomListItemOutPutDTO = z.infer<typeof RoomListItemOutPutDTOSchema>
|
||||
|
||||
export type RoomListItemSchema = z.infer< typeof roomListItemSchema>
|
||||
export type RoomListOutPutDTO = z.infer<typeof RoomListOutPutDTOSchema>
|
||||
|
||||
|
||||
@@ -60,7 +62,6 @@ export class GetRoomListUseCaseService {
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/list')
|
||||
async execute() {
|
||||
// console.log('update===============')
|
||||
const result = await this.roomRemoteDataSourceService.getRoomList()
|
||||
|
||||
const localList = await this.roomLocalDataSourceService.findAll()
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { IRoomRemoteRepository } from '../../repository/room/room-remote-repository';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoomSearchByNameService {
|
||||
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: IRoomRemoteRepository
|
||||
) { }
|
||||
|
||||
async execute(name: string) {
|
||||
const result = this.roomRemoteDataSourceService.search(name)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -37,10 +37,22 @@ const LoginUserResponseSchema = z.object({
|
||||
});
|
||||
|
||||
|
||||
|
||||
export type UserLoginOutputResponse = z.infer<typeof LoginUserResponseSchema>
|
||||
|
||||
const UserRefreshTokenInputSchema = z.object({
|
||||
authorization: z.string(),
|
||||
refreshToken: z.string(),
|
||||
channelId: z.number()
|
||||
})
|
||||
|
||||
export type UserRefreshTokenInputDTO = z.infer<typeof UserRefreshTokenInputSchema>
|
||||
|
||||
|
||||
|
||||
export type IUserRepositoryLoginParams = z.infer<typeof UserRepositoryLoginParams>
|
||||
export abstract class IUserRemoteRepository {
|
||||
abstract login(input: IUserRepositoryLoginParams): Promise<Result<HttpResult<UserLoginOutputResponse>, HttpErrorResponse>>
|
||||
abstract logout(): Promise<Result<HttpResult<any>, HttpErrorResponse>>
|
||||
abstract refreshToken(input:UserRefreshTokenInputDTO): Promise<Result<HttpResult<any>, HttpErrorResponse>>
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { z } from 'zod';
|
||||
import { z, ZodError, ZodSchema } from 'zod';
|
||||
import { IUserRemoteRepository } from '../repository/user-remote-repository';
|
||||
import { XTracerAsync, TracingType } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
import { zodSafeValidation } from 'src/app/utils/zodValidation';
|
||||
@@ -8,6 +8,8 @@ import { AESEncrypt } from 'src/app/services/aesencrypt.service';
|
||||
import { UserLoginMapper } from '../mapper/user-login';
|
||||
import { UserSession } from 'src/app/models/user.model';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { err, ok, Result } from 'neverthrow';
|
||||
import { error } from '../../../services/Either/index';
|
||||
|
||||
const UserLoginInputSchema = z.object({
|
||||
username: z.string(),
|
||||
@@ -36,6 +38,11 @@ const UserLoginOutputSchema = z.object({
|
||||
|
||||
export type UserLoginOutput = z.infer<typeof UserLoginOutputSchema>
|
||||
|
||||
export enum LoginError {
|
||||
userNotFound = 401,
|
||||
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -48,13 +55,13 @@ export class UserLoginUseCaseService {
|
||||
) { }
|
||||
|
||||
@XTracerAsync({name:'UserLoginUseCaseService', module:'user', bugPrint: true})
|
||||
async execute(input: UserLoginInput, tracing?: TracingType) {
|
||||
async execute(input: UserLoginInput, tracing?: TracingType): Promise<Result<UserLoginOutput, LoginError | ZodError<UserLoginInput>>> {
|
||||
const validation = zodSafeValidation<UserLoginInput>(UserLoginInputSchema, input)
|
||||
|
||||
if(validation.isOk()) {
|
||||
|
||||
let channelId;
|
||||
if ( this.platform.is('desktop') || this.platform.is("mobileweb")){
|
||||
if ( this.platform.is('desktop') || this.platform.is("mobileweb")) {
|
||||
channelId = 2
|
||||
} else {
|
||||
channelId = 1
|
||||
@@ -67,28 +74,21 @@ export class UserLoginUseCaseService {
|
||||
ChannelId: channelId
|
||||
})
|
||||
|
||||
return result.map(e => {
|
||||
if(result.isOk() && result.value.data.data) {
|
||||
|
||||
const data = UserLoginMapper.toDomainData(e.data)
|
||||
const data = UserLoginMapper.toDomainData(result.value.data);
|
||||
const session: UserSession = Object.assign(SessionStore.user, data);
|
||||
SessionStore.reset(session);
|
||||
|
||||
const session: UserSession = Object.assign(SessionStore.user, data)
|
||||
return ok(data)
|
||||
|
||||
if (session.RoleID == 100000014) {
|
||||
session.Profile = 'PR'
|
||||
} else if (session.RoleID == 100000011) {
|
||||
session.Profile = 'MDGPR'
|
||||
} else if (session.RoleID == 99999872) {
|
||||
session.Profile = 'Consultant'
|
||||
} else if (session.RoleID == 99999886) {
|
||||
session.Profile = 'SGGPR'
|
||||
} else {
|
||||
session.Profile = 'Unknown'
|
||||
}
|
||||
|
||||
SessionStore.reset(session)
|
||||
} else if (result.isOk() && !result.value.data.data) {
|
||||
return err(LoginError.userNotFound)
|
||||
}
|
||||
|
||||
return UserLoginMapper.toDomainData(e.data)
|
||||
})
|
||||
if(result.isErr() && result.error.status) {
|
||||
return err(result.error.status as LoginError)
|
||||
}
|
||||
|
||||
} else {
|
||||
tracing.setAttribute('parameter error','true')
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { z } from 'zod';
|
||||
import { IUserRemoteRepository } from '../repository/user-remote-repository';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { Platform } from '@ionic/angular';
|
||||
import { XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserRefreshTokenService {
|
||||
|
||||
constructor(
|
||||
private userRemoteRepository: IUserRemoteRepository,
|
||||
private platform: Platform
|
||||
) { }
|
||||
|
||||
@XTracerAsync({name:'UserRefreshTokenService', module:'user', bugPrint: true})
|
||||
async execute() {
|
||||
let channelId;
|
||||
if ( this.platform.is('desktop') || this.platform.is("mobileweb")){
|
||||
channelId = 2
|
||||
} else {
|
||||
channelId = 1
|
||||
}
|
||||
|
||||
return await this.userRemoteRepository.refreshToken({
|
||||
authorization: SessionStore.user.Authorization,
|
||||
refreshToken: SessionStore.user.RefreshToken,
|
||||
channelId
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user