business
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable } 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';
|
||||
|
||||
@Injectable()
|
||||
export class CatalogueService {
|
||||
create(createCatalogueDto: CreateCatalogueDto) {
|
||||
return 'This action adds a new catalogue';
|
||||
constructor(
|
||||
private readonly em: EntityManager,
|
||||
) { }
|
||||
|
||||
async create(dto: CreateCatalogueDto) {
|
||||
const business = await this.em.findOne(Business, {})
|
||||
if (!business) {
|
||||
throw new BadRequestException()
|
||||
}
|
||||
const catalogue = this.em.create(Catalogue, { ...dto, business })
|
||||
return this.em.persistAndFlush(catalogue)
|
||||
}
|
||||
|
||||
findAll() {
|
||||
|
||||
Reference in New Issue
Block a user