This commit is contained in:
@@ -10,10 +10,13 @@ import {
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { OrganizationRole } from './organization-role.entity';
|
||||
import { UuidBaseEntity } from '../../../common/entities/uuid-base.entity';
|
||||
import { Exclude } from 'class-transformer';
|
||||
|
||||
@Entity('organizations')
|
||||
export class Organization {
|
||||
export class Organization extends UuidBaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
@Exclude()
|
||||
id!: number;
|
||||
|
||||
@Column({ name: 'organization_code', length: 20, unique: true })
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
Delete,
|
||||
Query,
|
||||
UseGuards,
|
||||
ParseIntPipe,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { OrganizationService } from './organization.service.js';
|
||||
@@ -17,6 +16,7 @@ import { UpdateOrganizationDto } from './dto/update-organization.dto.js';
|
||||
import { SearchOrganizationDto } from './dto/search-organization.dto.js';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard.js';
|
||||
import { RequirePermission } from '../../common/decorators/require-permission.decorator.js';
|
||||
import { ParseUuidPipe } from '../../common/pipes/parse-uuid.pipe';
|
||||
|
||||
@ApiTags('Organizations')
|
||||
@ApiBearerAuth()
|
||||
@@ -38,26 +38,26 @@ export class OrganizationController {
|
||||
return this.orgService.findAll(query);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get Organization by ID' })
|
||||
findOne(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.orgService.findOne(id);
|
||||
@Get(':uuid')
|
||||
@ApiOperation({ summary: 'Get Organization by UUID' })
|
||||
findOne(@Param('uuid', ParseUuidPipe) uuid: string) {
|
||||
return this.orgService.findOneByUuid(uuid);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@Patch(':uuid')
|
||||
@RequirePermission('master_data.manage')
|
||||
@ApiOperation({ summary: 'Update Organization' })
|
||||
update(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Param('uuid', ParseUuidPipe) uuid: string,
|
||||
@Body() dto: UpdateOrganizationDto
|
||||
) {
|
||||
return this.orgService.update(id, dto);
|
||||
return this.orgService.update(uuid, dto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Delete(':uuid')
|
||||
@RequirePermission('master_data.manage')
|
||||
@ApiOperation({ summary: 'Delete Organization' })
|
||||
remove(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.orgService.remove(id);
|
||||
remove(@Param('uuid', ParseUuidPipe) uuid: string) {
|
||||
return this.orgService.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,17 +86,21 @@ export class OrganizationService {
|
||||
return org;
|
||||
}
|
||||
|
||||
async update(id: number, dto: UpdateOrganizationDto) {
|
||||
const org = await this.findOne(id);
|
||||
async findOneByUuid(uuid: string) {
|
||||
const org = await this.orgRepo.findOne({ where: { uuid } });
|
||||
if (!org)
|
||||
throw new NotFoundException(`Organization UUID ${uuid} not found`);
|
||||
return org;
|
||||
}
|
||||
|
||||
async update(uuid: string, dto: UpdateOrganizationDto) {
|
||||
const org = await this.findOneByUuid(uuid);
|
||||
Object.assign(org, dto);
|
||||
return this.orgRepo.save(org);
|
||||
}
|
||||
|
||||
async remove(id: number) {
|
||||
const org = await this.findOne(id);
|
||||
// Hard delete or Soft delete? Schema doesn't have deleted_at for Organization, but let's check.
|
||||
// Schema says: created_at, updated_at. No deleted_at.
|
||||
// So hard delete.
|
||||
async remove(uuid: string) {
|
||||
const org = await this.findOneByUuid(uuid);
|
||||
return this.orgRepo.remove(org);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user