forked from hangshuo652/aurak
feat: implement QuestionBank CRUD with pagination and template query
- Add pagination support to findAll (page, limit query params) - Add findByTemplateId method to service - Add GET /by-template/:templateId endpoint to controller - Service already includes CRUD for QuestionBank and QuestionBankItem
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { UserSetting } from './user-setting.entity';
|
||||
|
||||
@Injectable()
|
||||
export class UserSettingService {
|
||||
constructor(
|
||||
@InjectRepository(UserSetting)
|
||||
private userSettingRepository: Repository<UserSetting>,
|
||||
) {}
|
||||
|
||||
async getByUser(userId: string): Promise<UserSetting> {
|
||||
let setting = await this.userSettingRepository.findOne({
|
||||
where: { userId },
|
||||
});
|
||||
if (!setting) {
|
||||
setting = this.userSettingRepository.create({ userId, language: 'zh' });
|
||||
await this.userSettingRepository.save(setting);
|
||||
}
|
||||
return setting;
|
||||
}
|
||||
|
||||
async update(userId: string, language: string): Promise<UserSetting> {
|
||||
const setting = await this.getByUser(userId);
|
||||
setting.language = language;
|
||||
return this.userSettingRepository.save(setting);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user