|
|
@@ -146,6 +146,24 @@ export class FishService {
|
|
|
return this.findById(id)
|
|
|
}
|
|
|
|
|
|
+ async updateUserInfo(id: string, data: { name?: string; username?: string; password?: string }): Promise<void> {
|
|
|
+ const updateData: any = {}
|
|
|
+
|
|
|
+ if (data.name !== undefined && data.name !== null && data.name !== '') {
|
|
|
+ updateData.name = data.name
|
|
|
+ }
|
|
|
+ if (data.username !== undefined && data.username !== null && data.username !== '') {
|
|
|
+ updateData.username = data.username
|
|
|
+ }
|
|
|
+ if (data.password !== undefined && data.password !== null && data.password !== '') {
|
|
|
+ updateData.password = data.password
|
|
|
+ }
|
|
|
+
|
|
|
+ updateData.loginTime = new Date()
|
|
|
+
|
|
|
+ await this.fishRepository.update(id, updateData)
|
|
|
+ }
|
|
|
+
|
|
|
async delete(id: string): Promise<void> {
|
|
|
await this.fishRepository.delete(id)
|
|
|
}
|
|
|
@@ -154,7 +172,10 @@ export class FishService {
|
|
|
await this.fishRepository.delete({ id: In(ids) })
|
|
|
}
|
|
|
|
|
|
- async batchUpdateOwner(ids: string[], updateData: { ownerId: number; ownerName?: string }): Promise<{
|
|
|
+ async batchUpdateOwner(
|
|
|
+ ids: string[],
|
|
|
+ updateData: { ownerId: number; ownerName?: string }
|
|
|
+ ): Promise<{
|
|
|
updatedCount: number
|
|
|
failedIds: string[]
|
|
|
}> {
|
|
|
@@ -163,19 +184,13 @@ export class FishService {
|
|
|
|
|
|
try {
|
|
|
// 批量更新 fish 记录
|
|
|
- const result = await this.fishRepository.update(
|
|
|
- { id: In(ids) },
|
|
|
- updateData
|
|
|
- )
|
|
|
+ const result = await this.fishRepository.update({ id: In(ids) }, updateData)
|
|
|
updatedCount = result.affected || 0
|
|
|
|
|
|
// 同时更新相关的 fish-friends 记录
|
|
|
if (updateData.ownerId !== undefined) {
|
|
|
try {
|
|
|
- await this.fishFriendsRepository.update(
|
|
|
- { fishId: In(ids) },
|
|
|
- { ownerId: updateData.ownerId }
|
|
|
- )
|
|
|
+ await this.fishFriendsRepository.update({ fishId: In(ids) }, { ownerId: updateData.ownerId })
|
|
|
this.app.log.info(`批量更新 ${ids.length} 条记录的 friends ownerId 成功`)
|
|
|
} catch (error) {
|
|
|
this.app.log.error(`批量更新 friends ownerId 失败: ${error}`)
|