mirror of
https://git.meshkee.com/Meshkee/backend.git
synced 2026-08-11 22:30:59 +04:30
NestJS backend with Prisma, Docker Compose for Postgres/Redis, and deploy docs for the production VM.
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { Injectable, ForbiddenException } from '@nestjs/common';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
import { PermissionsService } from '../auth/permissions.service';
|
|
import { AuthUser } from '../auth/auth.types';
|
|
|
|
@Injectable()
|
|
export class BusinessCategoriesService {
|
|
constructor(
|
|
private readonly prisma: PrismaService,
|
|
private readonly permissions: PermissionsService,
|
|
) {}
|
|
|
|
async list(actor: AuthUser) {
|
|
const isSuperAdmin = await this.permissions.isSuperAdmin(actor.id);
|
|
const canRead =
|
|
isSuperAdmin ||
|
|
actor.roles.includes('business_owner') ||
|
|
actor.roles.includes('business_staff');
|
|
|
|
if (!canRead) {
|
|
throw new ForbiddenException('Access denied');
|
|
}
|
|
|
|
const categories = await this.prisma.businessCategory.findMany({
|
|
where: { isActive: true },
|
|
orderBy: [{ sortOrder: 'asc' }, { name: 'asc' }],
|
|
select: {
|
|
id: true,
|
|
parentId: true,
|
|
name: true,
|
|
slug: true,
|
|
description: true,
|
|
icon: true,
|
|
sortOrder: true,
|
|
},
|
|
});
|
|
|
|
return { items: categories };
|
|
}
|
|
}
|