import { UserWeChatDAO } from "../../../dao" ; import { EntityManager , InsertResult } from "typeorm" ; import { ControllerError } from "../../../error/ControllerError" ; import { ErrorCode } from "../../../ErrorCode" ; export class ServiceUserWeChat { constructor ( private readonly userUUID ) { } public async create ( data , t ? ) { const { userName , unionUUID , openUUID } = data ; return await UserWeChatDAO ( t ) . insert ( { user_uuid : this . userUUID , user_name : userName , union_uuid : unionUUID , open_uuid : openUUID , } ) ; } public async assertExist ( ) { const result = await UserWeChatDAO ( ) . findOne ( [ "id" ] , { user_uuid : this . userUUID , } ) ; if ( result === undefined ) { throw new ControllerError ( ErrorCode . UserNotFound ) ; } } public static async userUUIDByUnionUUID ( unionUUID ) { const result = await UserWeChatDAO ( ) . findOne ( [ "user_uuid" ] , { union_uuid : unionUUID , } ) ; return result ? result . user_uuid : null ; } }