style: apply standard ESLint & Prettier formatting across backend
Deploy Canina / deploy (push) Successful in 4m58s
Deploy Canina / deploy (push) Successful in 4m58s
This commit is contained in:
1 parent
ae636c8b03
commit
62bd8811fa
66 files changed
+1398
-607
No files matched your search
@@ -1,13 +1,19 @@
|
||||
import { Controller, Get, Param, HttpStatus, Query } from '@nestjs/common';
|
||||
import { WikiService } from './wiki.service';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiOkResponse, ApiNotFoundResponse } from '@nestjs/swagger';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiOkResponse,
|
||||
ApiNotFoundResponse,
|
||||
} from '@nestjs/swagger';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
|
||||
@ApiTags('Wiki - دانشنامه ترکیبات')
|
||||
@Controller('wiki')
|
||||
@ApiResponse({
|
||||
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
description: 'خطای داخلی سرور'
|
||||
description: 'خطای داخلی سرور',
|
||||
})
|
||||
export class WikiController {
|
||||
constructor(private readonly wikiService: WikiService) {}
|
||||
|
||||
@@ -7,10 +7,16 @@ export class WikiService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll(filters: PaginationDto) {
|
||||
const { search, page = 1, limit = 10, sortBy: rawSortBy = 'term', sortOrder = 'asc' } = filters;
|
||||
const {
|
||||
search,
|
||||
page = 1,
|
||||
limit = 10,
|
||||
sortBy: rawSortBy = 'term',
|
||||
sortOrder = 'asc',
|
||||
} = filters;
|
||||
const allowedSortFields = ['key', 'term', 'wikiId'];
|
||||
const sortBy = allowedSortFields.includes(rawSortBy) ? rawSortBy : 'term';
|
||||
|
||||
|
||||
const whereClause: any = {};
|
||||
if (search) {
|
||||
whereClause.OR = [
|
||||
@@ -28,7 +34,7 @@ export class WikiService {
|
||||
take: limit,
|
||||
orderBy: { [sortBy]: sortOrder },
|
||||
}),
|
||||
this.prisma.scientificTerm.count({ where: whereClause })
|
||||
this.prisma.scientificTerm.count({ where: whereClause }),
|
||||
]);
|
||||
|
||||
return {
|
||||
@@ -38,13 +44,13 @@ export class WikiService {
|
||||
page,
|
||||
lastPage: Math.ceil(total / limit),
|
||||
limit,
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async findOneByKey(key: string) {
|
||||
const term = await this.prisma.scientificTerm.findUnique({
|
||||
where: { key }
|
||||
where: { key },
|
||||
});
|
||||
if (!term) throw new NotFoundException('Wiki term not found');
|
||||
return term;
|
||||
|
||||
Reference in new issue
Block a user