This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
55 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import { Controller, Post, Body } from '@nestjs/common'; | ||
import { ManufacturerService } from './manufacturer.service'; | ||
import { CreateManufacturerDto } from './dto/create-manufacturer.dto'; | ||
|
||
@Controller('manufacturer') | ||
export class ManufacturerController { | ||
constructor(private readonly manufacturerService: ManufacturerService) {} | ||
|
||
@Post('register') | ||
async registerManufacturer( | ||
@Body() createManufacturerDto: CreateManufacturerDto | ||
) { | ||
return this.manufacturerService.registerManufacturer(createManufacturerDto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
Injectable, | ||
ConflictException, | ||
InternalServerErrorException, | ||
} from '@nestjs/common'; | ||
import { PrismaService } from 'src/prisma/prisma.service'; | ||
import { CreateManufacturerDto } from './dto/create-manufacturer.dto'; | ||
|
||
@Injectable() | ||
export class ManufacturerService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
async registerManufacturer(createManufacturerDto: CreateManufacturerDto) { | ||
const { name, address, email, rc, phone } = createManufacturerDto; | ||
|
||
try { | ||
return await this.prisma.manufacturer.create({ | ||
data: { | ||
name, | ||
address, | ||
email, | ||
rc, | ||
phone, | ||
}, | ||
}); | ||
} catch (error) { | ||
if (error.code === 'P2002') { | ||
throw new ConflictException( | ||
'Manufacturer with this email or name already exists' | ||
); | ||
} | ||
throw new InternalServerErrorException('Failed to register manufacturer'); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.