import { UserDAO } from "../../../dao" ; import { Gender } from "../../../constants/Project" ; import { EntityManager , InsertResult } from "typeorm" ; import { ControllerError } from "../../../error/ControllerError" ; import { ErrorCode } from "../../../ErrorCode" ; import { UpdateResult } from "typeorm/query-builder/result/UpdateResult" ; export class ServiceUser { constructor ( private readonly userUUID ) { } public async create ( data , t ? ) { const { userName , avatarURL , gender } = data ; return await UserDAO ( t ) . insert ( { user_name : userName , user_uuid : this . userUUID , avatar_url : avatarURL , gender , user_password : "" , } ) ; } public async nameAndAvatar ( ) { const result = await UserDAO ( ) . findOne ( [ "user_name" , "avatar_url" ] , { user_uuid : this . userUUID , } ) ; if ( result ) { return { userName : result . user_name , avatarURL : result . avatar_url , } ; } return null ; } public async assertGetNameAndAvatar ( ) { const result = await this . nameAndAvatar ( ) ; if ( result === null ) { throw new ControllerError ( ErrorCode . UserNotFound ) ; } return result ; } public async updateName ( userName , t ? ) { return await UserDAO ( t ) . update ( { user_name : userName , } , { user_uuid : this . userUUID , } ) ; } }