business
This commit is contained in:
@@ -17,8 +17,5 @@ export class CreateAdminDto {
|
||||
@IsString()
|
||||
lastName?: string;
|
||||
|
||||
@ApiProperty({ description: 'Role id for the admin' })
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
roleId!: string;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { BusinessService } from './business.service';
|
||||
import { CreateBusinessDto } from './dto/create-business.dto';
|
||||
import { SetupBusinessDto } from './dto/create-business.dto';
|
||||
import { UpdateBusinessDto } from './dto/update-business.dto';
|
||||
|
||||
@Controller('business')
|
||||
export class BusinessController {
|
||||
constructor(private readonly businessService: BusinessService) {}
|
||||
constructor(private readonly businessService: BusinessService) { }
|
||||
|
||||
@Post()
|
||||
create(@Body() createBusinessDto: CreateBusinessDto) {
|
||||
return this.businessService.create(createBusinessDto);
|
||||
create(@Body() createBusinessDto: SetupBusinessDto) {
|
||||
return this.businessService.setupAccount(createBusinessDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateBusinessDto } from './dto/create-business.dto';
|
||||
import { SetupBusinessDto } from './dto/create-business.dto';
|
||||
import { UpdateBusinessDto } from './dto/update-business.dto';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { Business } from './entities/business.entity';
|
||||
@@ -13,13 +13,28 @@ export class BusinessService {
|
||||
private readonly businessRepository: BusinessRepository
|
||||
) { }
|
||||
|
||||
async create(dto: CreateBusinessDto) {
|
||||
const admin = await this.em.findOne(Admin, {})
|
||||
if (!admin) {
|
||||
throw new BadRequestException()
|
||||
}
|
||||
const business = this.em.create(Business, { ...dto, admin })
|
||||
await this.em.persistAndFlush(business)
|
||||
async setupAccount(dto: SetupBusinessDto) {
|
||||
const { danakSubscriptionId, name, phone, slug, firstName, lastName } = dto
|
||||
|
||||
const business = await this.em.transactional(async (em) => {
|
||||
const business = em.create(Business, {
|
||||
danakSubscriptionId,
|
||||
name,
|
||||
slug
|
||||
})
|
||||
|
||||
const admin = em.create(Admin, {
|
||||
firstName,
|
||||
lastName,
|
||||
phone,
|
||||
business
|
||||
})
|
||||
|
||||
await em.persistAndFlush([business, admin])
|
||||
|
||||
return business
|
||||
})
|
||||
|
||||
return business
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
|
||||
import { IsString, IsOptional, IsBoolean, IsInt, Min, IsEnum } from 'class-validator';
|
||||
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
import { IsNotEmpty, IsOptional, IsString, } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class CreateBusinessDto {
|
||||
export class SetupBusinessDto {
|
||||
@IsString()
|
||||
@ApiProperty({ example: '01619684-aebc-47d4-acc4-2e912a3d9dce' })
|
||||
danakSubscriptionId: string;
|
||||
|
||||
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@@ -18,6 +14,19 @@ export class CreateBusinessDto {
|
||||
@ApiProperty()
|
||||
slug: string;
|
||||
|
||||
|
||||
@ApiProperty({ description: 'Mobile phone number' })
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
phone!: string;
|
||||
|
||||
@ApiProperty({ description: 'First name', required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
firstName?: string;
|
||||
|
||||
@ApiProperty({ description: 'Last name', required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
lastName?: string;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreateBusinessDto } from './create-business.dto';
|
||||
import { SetupBusinessDto } from './create-business.dto';
|
||||
|
||||
export class UpdateBusinessDto extends PartialType(CreateBusinessDto) {}
|
||||
export class UpdateBusinessDto extends PartialType(SetupBusinessDto) { }
|
||||
|
||||
@@ -40,7 +40,7 @@ export class Business extends BaseEntity {
|
||||
catalogues = new Collection<Catalogue>(this);
|
||||
|
||||
@OneToOne(() => Admin, (admin) => admin.business, { deleteRule: 'restrict' })
|
||||
admin: Admin
|
||||
admin: Admin & Opt
|
||||
|
||||
|
||||
[EntityRepositoryType]?: BusinessRepository;
|
||||
|
||||
Reference in New Issue
Block a user