catalogue
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateCatalogueDto } from './dto/create-catalogue.dto';
|
||||
import { UpdateCatalogueDto } from './dto/update-catalogue.dto';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { Catalogue } from './entities/catalogue.entity';
|
||||
import { Business } from '../business/entities/business.entity';
|
||||
import { CatalogueStatus } from './enums/company-status.enum';
|
||||
import { CatalogueRepository } from './repositories/catalogue.repository';
|
||||
import { FindCataloguesDto } from './dto/find-catalogues.dto';
|
||||
|
||||
@Injectable()
|
||||
export class CatalogueService {
|
||||
constructor(
|
||||
private readonly em: EntityManager,
|
||||
private readonly catalogueRepository: CatalogueRepository
|
||||
) { }
|
||||
|
||||
async create(dto: CreateCatalogueDto) {
|
||||
@@ -18,23 +21,38 @@ export class CatalogueService {
|
||||
throw new BadRequestException()
|
||||
}
|
||||
const catalogue = this.em.create(Catalogue,
|
||||
{ ...dto, business, status: CatalogueStatus.PENDING })
|
||||
{ ...dto, business, status: CatalogueStatus.PENDING })
|
||||
return this.em.persistAndFlush(catalogue)
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all catalogue`;
|
||||
findAll(dto: FindCataloguesDto) {
|
||||
return this.catalogueRepository.findAllPaginated(dto)
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} catalogue`;
|
||||
async findOne(id: string) {
|
||||
const catalogue = await this.findOneOrFail(id)
|
||||
return catalogue
|
||||
}
|
||||
|
||||
update(id: number, updateCatalogueDto: UpdateCatalogueDto) {
|
||||
return `This action updates a #${id} catalogue`;
|
||||
async findOneOrFail(id: string) {
|
||||
const catalogue = await this.catalogueRepository.findOne({ id })
|
||||
if (!catalogue) {
|
||||
throw new NotFoundException("catalogue not found")
|
||||
}
|
||||
return catalogue
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} catalogue`;
|
||||
async update(id: string, dto: UpdateCatalogueDto) {
|
||||
const catalogue = await this.findOneOrFail(id)
|
||||
this.em.assign(catalogue, dto)
|
||||
await this.em.flush()
|
||||
return catalogue
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
const catalogue = await this.findOneOrFail(id)
|
||||
catalogue.deletedAt = new Date()
|
||||
await this.em.flush()
|
||||
return catalogue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user