Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat(account): add clientType to account DTO and repository (#338)
nevina9b8ea73772b
diff --git a/project/backend/apps/aitoearn-server/src/account/dto/account.dto.ts b/project/backend/apps/aitoearn-server/src/account/dto/account.dto.tsindex ae753987..5d83d3e0 100644--- a/project/backend/apps/aitoearn-server/src/account/dto/account.dto.ts+++ b/project/backend/apps/aitoearn-server/src/account/dto/account.dto.ts@@ -1,11 +1,12 @@import { AccountType, createZodDto } from '@yikart/common'-import { AccountStatus } from '@yikart/mongodb'+import { AccountStatus, ClientType } from '@yikart/mongodb'import { z } from 'zod'const CreateAccountSchema = z.object({refresh_token: z.string().min(1).optional(),access_token: z.string().min(1).optional(),type: z.enum(AccountType),+ clientType: z.enum(ClientType).optional(),loginCookie: z.string().min(1).optional(),loginTime: z.coerce.date().optional(),uid: z.string().min(1),@@ -33,6 +34,7 @@ const UpdateAccountSchema = z.object({refresh_token: z.string().min(1).optional(),access_token: z.string().min(1).optional(),type: z.enum(AccountType).optional(),+ clientType: z.enum(ClientType).optional(),loginCookie: z.string().min(1).optional(),loginTime: z.coerce.date().optional(),uid: z.string().min(1).optional(),diff --git a/project/backend/libs/mongodb/src/repositories/account.repository.ts b/project/backend/libs/mongodb/src/repositories/account.repository.tsindex ba04bffa..9d37c1fc 100644--- a/project/backend/libs/mongodb/src/repositories/account.repository.ts+++ b/project/backend/libs/mongodb/src/repositories/account.repository.ts@@ -30,15 +30,16 @@ export class AccountRepository extends BaseRepository<Account> {}async addAccount(data: Partial<Account>): Promise<Account> {+ const { clientType, type, uid } = dataconst info: Account | null = await this.accountModel.findOne({- type: data.type,- uid: data.uid,+ type,+ uid,})if (info) {await this.accountModel.updateOne({- type: data.type,- uid: data.uid,+ type,+ uid,}, {...data,status: AccountStatus.NORMAL,@@ -46,13 +47,20 @@ export class AccountRepository extends BaseRepository<Account> {})}else {- data['_id'] = `${data.type}_${data.uid}`+ let newId = `${type}_${uid}`+ if (+ [AccountType.Xhs, AccountType.Douyin].includes(type as AccountType)+ ) {+ newId += `_${clientType}`+ data.clientType = clientType+ }+ data['_id'] = newIdawait this.accountModel.create({ ...data })}return (await this.accountModel.findOne({- type: data.type,- uid: data.uid,+ type,+ uid,}))!}diff --git a/project/backend/libs/mongodb/src/schemas/account.schema.ts b/project/backend/libs/mongodb/src/schemas/account.schema.tsindex f4910377..94d69f28 100644--- a/project/backend/libs/mongodb/src/schemas/account.schema.ts+++ b/project/backend/libs/mongodb/src/schemas/account.schema.ts@@ -9,6 +9,11 @@ export enum AccountStatus {ABNORMAL = 0,}+export enum ClientType {+ WEB = 'web',+ APP = 'app',+}+@Schema({collection: 'account',versionKey: false,@@ -35,6 +40,12 @@ export class Account extends WithTimestampSchema {})type: AccountType+ @Prop({+ required: false,+ enum: ClientType,+ })+ clientType?: ClientType+@Prop({required: true,index: true,