38 lines
1007 B
TypeScript
38 lines
1007 B
TypeScript
|
|
import { Injectable } from '@nestjs/common';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class UsersRepository {
|
||
|
|
private profiles: Map<string, any> = new Map();
|
||
|
|
private preferences: Map<string, any> = new Map();
|
||
|
|
|
||
|
|
async findProfileByUserId(userId: string) {
|
||
|
|
return this.profiles.get(userId) || {
|
||
|
|
userId,
|
||
|
|
nickname: '学习者',
|
||
|
|
learningDirection: '',
|
||
|
|
bio: '',
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
async updateProfile(userId: string, dto: any) {
|
||
|
|
const existing = (await this.findProfileByUserId(userId)) || {};
|
||
|
|
const updated = { ...existing, ...dto };
|
||
|
|
this.profiles.set(userId, updated);
|
||
|
|
return updated;
|
||
|
|
}
|
||
|
|
|
||
|
|
async updatePreferences(userId: string, dto: any) {
|
||
|
|
const existing = this.preferences.get(userId) || {
|
||
|
|
userId,
|
||
|
|
defaultFocusMinutes: 25,
|
||
|
|
aiSuggestionLevel: 'normal',
|
||
|
|
language: 'zh-CN',
|
||
|
|
appearance: 'system',
|
||
|
|
notificationEnabled: true,
|
||
|
|
};
|
||
|
|
const updated = { ...existing, ...dto };
|
||
|
|
this.preferences.set(userId, updated);
|
||
|
|
return updated;
|
||
|
|
}
|
||
|
|
}
|