update
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Controller, Post, Body, HttpCode, HttpStatus } from '@nestjs/common';
|
||||
import { Controller, Post, Body, HttpCode, HttpStatus, Get } from '@nestjs/common';
|
||||
import { AdminService } from './admin.service';
|
||||
import { CreateAdminDto } from './dto/create-admin.dto';
|
||||
import { ApiTags, ApiOperation, ApiBody, ApiResponse } from '@nestjs/swagger';
|
||||
@@ -8,6 +8,14 @@ import { ApiTags, ApiOperation, ApiBody, ApiResponse } from '@nestjs/swagger';
|
||||
export class AdminController {
|
||||
constructor(private readonly adminService: AdminService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'admin' })
|
||||
@ApiResponse({ status: 201, description: 'Admins' })
|
||||
async getAll() {
|
||||
const admin = await this.adminService.findAll();
|
||||
return admin;
|
||||
}
|
||||
|
||||
@Post()
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@ApiOperation({ summary: 'Create a new admin' })
|
||||
|
||||
@@ -21,6 +21,9 @@ export class AdminService {
|
||||
async findById(id: string): Promise<Admin | null> {
|
||||
return this.adminRepository.findOne({ id });
|
||||
}
|
||||
async findAll(): Promise<Admin[]> {
|
||||
return this.adminRepository.findAll();
|
||||
}
|
||||
|
||||
async create(data: { phone: string; firstName?: string; lastName?: string; roleId: string; restId: string }) {
|
||||
const { phone, firstName, lastName, roleId, restId } = data;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsOptional, IsString, IsNumber } from 'class-validator';
|
||||
import { IsOptional, IsString, IsNumber, Min } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export class FindRolesDto {
|
||||
@ApiProperty({ description: 'Search by role name', required: false })
|
||||
@@ -14,11 +15,15 @@ export class FindRolesDto {
|
||||
|
||||
@ApiProperty({ description: 'Page number', required: false, default: 1 })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
page?: number;
|
||||
|
||||
@ApiProperty({ description: 'Items per page', required: false, default: 20 })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Entity, ManyToOne, OneToOne, Property, Unique } from '@mikro-orm/core';
|
||||
import { Entity, ManyToOne, OneToOne, Property } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Restaurant } from '../../../modules/restaurants/entities/restaurant.entity';
|
||||
import { Role } from './role.entity';
|
||||
|
||||
@Entity({ tableName: 'admins' })
|
||||
// Add the Unique constraint for the combination of 'phone' and 'restaurant'
|
||||
@Unique({ properties: ['phone', 'restaurant'] })
|
||||
// @Unique({ properties: ['phone', 'restaurant'] })
|
||||
export class Admin extends BaseEntity {
|
||||
@Property({ nullable: true })
|
||||
firstName?: string;
|
||||
|
||||
@@ -9,6 +9,10 @@ export class AdminRepository extends EntityRepository<Admin> {
|
||||
}
|
||||
|
||||
async findByPhoneAndrestaurantSlug(phone: string, slug: string): Promise<Admin | null> {
|
||||
return this.findOne({ phone, restaurant: { slug } }, { populate: ['restaurant', 'role', 'role.permissions'] });
|
||||
return this.em.findOne(
|
||||
Admin,
|
||||
{ phone, restaurant: { slug } },
|
||||
{ populate: ['restaurant', 'role', 'role.permissions'] },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user