feat: complete admin url query sync, full sorting/filters, latin search, product media players, personalized pet name and stage noindex
Deploy Canina / deploy (push) Successful in 1m57s
Deploy Canina / deploy (push) Successful in 1m57s
This commit is contained in:
1 parent
d5c05b7577
commit
27a1517464
23 files changed
+168815
-46100
No files matched your search
@@ -20,6 +20,11 @@ export class PaginationQuery {
|
||||
role?: string;
|
||||
categoryId?: string;
|
||||
status?: string;
|
||||
sortBy?: string;
|
||||
sortOrder?: 'asc' | 'desc';
|
||||
suitableFor?: string;
|
||||
minPrice?: number | string;
|
||||
maxPrice?: number | string;
|
||||
}
|
||||
|
||||
export class CouponTargetInput {
|
||||
@@ -114,12 +119,17 @@ export class AdminService {
|
||||
}
|
||||
}
|
||||
|
||||
const sortField = (query.sortBy && typeof query.sortBy === 'string' && ['createdAt', 'firstName', 'lastName', 'mobile', 'email', 'role', 'walletBalance'].includes(query.sortBy))
|
||||
? query.sortBy
|
||||
: 'createdAt';
|
||||
const sortDirection = query.sortOrder === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.user.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
orderBy: { [sortField]: sortDirection },
|
||||
include: {
|
||||
addresses: true,
|
||||
walletTransactions: {
|
||||
@@ -274,22 +284,59 @@ export class AdminService {
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const where: Prisma.ProductWhereInput = {};
|
||||
const andConditions: Prisma.ProductWhereInput[] = [];
|
||||
|
||||
if (query.search) {
|
||||
where.OR = [
|
||||
{ nameFa: { contains: query.search, mode: 'insensitive' } },
|
||||
{ artNo: { contains: query.search } },
|
||||
];
|
||||
const trimmed = query.search.trim();
|
||||
andConditions.push({
|
||||
OR: [
|
||||
{ nameFa: { contains: trimmed, mode: 'insensitive' } },
|
||||
{ nameEn: { contains: trimmed, mode: 'insensitive' } },
|
||||
{ artNo: { contains: trimmed, mode: 'insensitive' } },
|
||||
{ barcode: { contains: trimmed, mode: 'insensitive' } },
|
||||
{ slug: { contains: trimmed, mode: 'insensitive' } },
|
||||
{ description: { contains: trimmed, mode: 'insensitive' } },
|
||||
{ shortDescription: { contains: trimmed, mode: 'insensitive' } },
|
||||
{ scientificTagline: { contains: trimmed, mode: 'insensitive' } },
|
||||
{
|
||||
symptoms: {
|
||||
some: {
|
||||
symptom: { contains: trimmed, mode: 'insensitive' },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
category: {
|
||||
name: { contains: trimmed, mode: 'insensitive' },
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (query.categoryId) {
|
||||
where.categoryId = query.categoryId;
|
||||
andConditions.push({ categoryId: query.categoryId });
|
||||
}
|
||||
|
||||
if (query.suitableFor && query.suitableFor !== 'all') {
|
||||
andConditions.push({ suitableFor: { in: [query.suitableFor, 'سگ و گربه', 'هر دو'] } });
|
||||
}
|
||||
|
||||
if (andConditions.length > 0) {
|
||||
where.AND = andConditions;
|
||||
}
|
||||
|
||||
const sortField = (query.sortBy && typeof query.sortBy === 'string' && ['nameFa', 'artNo', 'priceValue', 'packageSize', 'createdAt', 'updatedAt'].includes(query.sortBy))
|
||||
? query.sortBy
|
||||
: 'createdAt';
|
||||
const sortDirection = query.sortOrder === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.product.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
orderBy: { [sortField]: sortDirection },
|
||||
include: { category: true, symptoms: true },
|
||||
}),
|
||||
this.prisma.product.count({ where }),
|
||||
@@ -441,12 +488,17 @@ export class AdminService {
|
||||
where.status = query.status;
|
||||
}
|
||||
|
||||
const sortField = (query.sortBy && typeof query.sortBy === 'string' && ['createdAt', 'totalAmount', 'status', 'finalAmount'].includes(query.sortBy))
|
||||
? query.sortBy
|
||||
: 'createdAt';
|
||||
const sortDirection = query.sortOrder === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.order.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
orderBy: { [sortField]: sortDirection },
|
||||
include: {
|
||||
user: true,
|
||||
orderItems: {
|
||||
|
||||
Reference in new issue
Block a user