feat: add user submission functionality

This commit is contained in:
2026-07-05 21:45:45 +03:30
parent afb5045cf0
commit 7b44542ce7
48 changed files with 1459 additions and 55 deletions
@@ -1,6 +1,6 @@
import { HttpStatus, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { FindOneOptions, Repository } from 'typeorm';
import { PaginatedResponse } from '@/common/responses';
import { AppTimeoutException } from '@/common/exceptions/app-timeout.exception';
import { FindTestsDTO } from '../dtos/find-tests.dto';
@@ -64,12 +64,27 @@ export class TestsQueryProvider {
}
}
public async findOneForAdmin(id: number) {
public async findOneForAdmin(id: number, options?: FindOneOptions<Test>) {
let test: Test | null = null;
try {
return await this.testRepository.findOneBy({ id });
test = await this.testRepository.findOne({
where: { id },
...options,
});
} catch (err) {
throw new AppTimeoutException(err);
}
if (!test) {
throw new AppException(
'common.errors.entityNotFound',
HttpStatus.NOT_FOUND,
{ entity: '$t(tests.fields.test)' },
);
}
return test;
}
public async findOneForUser(id: number) {
+4 -2
View File
@@ -4,6 +4,8 @@ import { UpdateTestDTO } from '../dtos/update-test.dto';
import { FindTestsDTO } from '../dtos/find-tests.dto';
import { TestsQueryProvider } from './tests-query.provider';
import { TestsCommandProvider } from './tests-command.provider';
import { FindOneOptions } from 'typeorm';
import { Test } from '../entities/test.entity';
@Injectable()
export class TestsService {
@@ -31,8 +33,8 @@ export class TestsService {
return await this.testsQueryProvider.findAllForUser();
}
public async adminGetOne(id: number) {
return await this.testsQueryProvider.findOneForAdmin(id);
public async adminGetOne(id: number, options?: FindOneOptions<Test>) {
return await this.testsQueryProvider.findOneForAdmin(id, options);
}
public async userGetOne(id: number) {