feat: complete backend swagger annotations, admin pages pagination, and frontend application fixes
This commit is contained in:
1 parent
24137beb32
commit
2851ef8a25
41 files changed
+478
-128
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { Controller, Get, Param, HttpStatus } from '@nestjs/common';
|
||||
import { Controller, Get, Param, HttpStatus, Query } from '@nestjs/common';
|
||||
import { WikiService } from './wiki.service';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiOkResponse, ApiNotFoundResponse } from '@nestjs/swagger';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
|
||||
@ApiTags('Wiki - دانشنامه ترکیبات')
|
||||
@Controller('wiki')
|
||||
@@ -13,9 +14,9 @@ export class WikiController {
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'دریافت تمام کلمات دانشنامه' })
|
||||
@ApiOkResponse({ description: 'لیست تمامی ترکیبات علمی' })
|
||||
findAll() {
|
||||
return this.wikiService.findAll();
|
||||
@ApiOkResponse({ description: 'لیست کلمات به همراه توضیحات (صفحهبندی شده)' })
|
||||
findAll(@Query() query: PaginationDto) {
|
||||
return this.wikiService.findAll(query);
|
||||
}
|
||||
|
||||
@Get(':key')
|
||||
|
||||
@@ -1,14 +1,43 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
|
||||
@Injectable()
|
||||
export class WikiService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll() {
|
||||
return this.prisma.scientificTerm.findMany({
|
||||
orderBy: { term: 'asc' }
|
||||
});
|
||||
async findAll(filters: PaginationDto) {
|
||||
const { search, page = 1, limit = 10, sortBy = 'term', sortOrder = 'asc' } = filters;
|
||||
|
||||
const whereClause: any = {};
|
||||
if (search) {
|
||||
whereClause.OR = [
|
||||
{ term: { contains: search, mode: 'insensitive' } },
|
||||
{ definition: { contains: search, mode: 'insensitive' } },
|
||||
];
|
||||
}
|
||||
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.scientificTerm.findMany({
|
||||
where: whereClause,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { [sortBy]: sortOrder },
|
||||
}),
|
||||
this.prisma.scientificTerm.count({ where: whereClause })
|
||||
]);
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: {
|
||||
total,
|
||||
page,
|
||||
lastPage: Math.ceil(total / limit),
|
||||
limit,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async findOneByKey(key: string) {
|
||||
|
||||
Reference in new issue
Block a user