Skip to content

Commit

Permalink
feat: add option to add customerNumber Id on customer create.
Browse files Browse the repository at this point in the history
  • Loading branch information
rehmankha73 committed Jan 14, 2025
1 parent fe7a003 commit 674a30b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
13 changes: 12 additions & 1 deletion src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ConflictException,
forwardRef,
HttpStatus,
Inject,
Expand Down Expand Up @@ -146,7 +147,17 @@ export class AuthService {

data.role = role._id.toString();

data.odooCustomerId = await this.personService.getLastOdooCustomerId();
if (data.odooCustomerId) {
const customer = await this.personService.findOneByQuery({
odooCustomerId: data.odooCustomerId,
});
if (customer)
throw new ConflictException(
'Customer with the same customer number already exist in system!'
);
} else {
data.odooCustomerId = await this.personService.getLastOdooCustomerId();
}

data.session = new Date();

Expand Down
5 changes: 4 additions & 1 deletion src/modules/auth/dto/sign-up-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsISO8601, IsMongoId, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { IsISO8601, IsMongoId, IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator';

export class AdminCreateUserRequest {
@ApiProperty()
Expand Down Expand Up @@ -67,6 +67,9 @@ export class MobileSignUpRequest {

role?: string;

@ApiProperty()
@IsOptional()
@IsNumber()
odooCustomerId?: number;

@ApiProperty()
Expand Down
4 changes: 3 additions & 1 deletion src/modules/person/dto/person.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export class PersonCreateDto {
@IsNumber()
customerNumber?: number;

@ApiProperty()
@IsOptional()
@IsNumber()
odooCustomerId?: number;

@ApiProperty()
Expand Down Expand Up @@ -346,7 +349,6 @@ export class PersonFiltersDto {
@ApiProperty({ description: 'Filter object' })
@IsOptional()
@IsObject()
// filters?: Record<string, any>;
filters?: filterPayload;

@ApiProperty({ description: 'PopulatedFilter object' })
Expand Down
24 changes: 13 additions & 11 deletions src/modules/person/person.controller.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import {
Body,
ConflictException,
Controller,
Delete,
Get,
Param,
Patch,
Post,
Query,
Res,
UploadedFile,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import {
ApiBadRequestResponse,
ApiBearerAuth,
ApiBody,
ApiConsumes,
ApiInternalServerErrorResponse,
ApiNotAcceptableResponse,
ApiNotFoundResponse,
Expand All @@ -27,8 +23,6 @@ import {
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import {
BulkUploadDto,
BulkUploadResponseDto,
PaginatedPersonResponseDto,
PasswordUpdateRequestDto,
PersonCreateDto,
Expand All @@ -39,9 +33,6 @@ import {
UpdateFcmTokenRequestDto,
} from './dto/person.dto';
import { PersonService } from './person.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { AuthGuard } from '@nestjs/passport';
import { Response } from 'express';

@ApiBearerAuth('access-token')
@ApiTags('Person')
Expand All @@ -63,7 +54,18 @@ export class PersonController {
})
@Post()
async create(@Body() data: PersonCreateDto): Promise<any> {
data.odooCustomerId = await this.service.getLastOdooCustomerId();
if (data.odooCustomerId) {
const customer = await this.service.findOneByQuery({
odooCustomerId: data.odooCustomerId,
});
if (customer)
throw new ConflictException(
'Customer with the same customer number already exist in system!'
);
} else {
data.odooCustomerId = await this.service.getLastOdooCustomerId();
}

return await this.service.create(data);
}

Expand Down

0 comments on commit 674a30b

Please sign in to comment.