Merge branch 'development' of gitlab.com:empatnusabangsa/ppob/ppob-backend into development
# Conflicts: # package.json
This commit is contained in:
commit
a3ce252e3c
|
@ -1,8 +1,7 @@
|
||||||
import { Controller, Post, UseGuards, Request, Get } from '@nestjs/common';
|
import { Controller, Get, Post, Request, UseGuards } from '@nestjs/common';
|
||||||
import { LocalAuthGuard } from './local-auth.guard';
|
import { LocalAuthGuard } from './local-auth.guard';
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import { JwtAuthGuard } from './jwt-auth.guard';
|
import { Public } from './public.decorator';
|
||||||
import {Public} from "./public.decorator";
|
|
||||||
|
|
||||||
@Controller({
|
@Controller({
|
||||||
path: 'auth',
|
path: 'auth',
|
||||||
|
@ -18,9 +17,8 @@ export class AuthController {
|
||||||
return this.authService.login(req.user);
|
return this.authService.login(req.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
|
||||||
@Get('profile')
|
@Get('profile')
|
||||||
getProfile(@Request() req) {
|
getProfile(@Request() req) {
|
||||||
return req.user;
|
return this.authService.getProfile(req.user.userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,4 +35,8 @@ export class AuthService {
|
||||||
access_token: this.jwtService.sign(payload),
|
access_token: this.jwtService.sign(payload),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getProfile = async (userId: string) => {
|
||||||
|
return this.usersService.findOne(userId);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
5
src/users/dto/update-partner.dto.ts
Normal file
5
src/users/dto/update-partner.dto.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
|
import { CreatePartnerDto } from './create-partner.dto';
|
||||||
|
|
||||||
|
export class UpdatePartnerDto extends PartialType(CreatePartnerDto) {
|
||||||
|
}
|
4
src/users/dto/update-supplier.dto.ts
Normal file
4
src/users/dto/update-supplier.dto.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
|
import { CreateSupplierDto } from './create-supplier.dto';
|
||||||
|
|
||||||
|
export class UpdateSupplierDto extends PartialType(CreateSupplierDto) {}
|
|
@ -6,13 +6,15 @@ import {
|
||||||
Injectable,
|
Injectable,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Connection, EntityNotFoundError, Repository } from 'typeorm';
|
import { Connection, Not, Repository } from 'typeorm';
|
||||||
import { CoaService } from '../../transaction/coa.service';
|
import { CoaService } from '../../transaction/coa.service';
|
||||||
import { CreatePartnerDto } from '../dto/create-partner.dto';
|
import { CreatePartnerDto } from '../dto/create-partner.dto';
|
||||||
import { Partner } from '../entities/partner.entity';
|
import { Partner } from '../entities/partner.entity';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import { UsersService } from '../users.service';
|
import { UsersService } from '../users.service';
|
||||||
import { CreateUserDto } from '../dto/create-user.dto';
|
import { CreateUserDto } from '../dto/create-user.dto';
|
||||||
|
import { UpdatePartnerDto } from '../dto/update-partner.dto';
|
||||||
|
import { UpdateUserDto } from '../dto/update-user.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PartnerService {
|
export class PartnerService {
|
||||||
|
@ -38,7 +40,7 @@ export class PartnerService {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.NOT_ACCEPTABLE,
|
statusCode: HttpStatus.NOT_ACCEPTABLE,
|
||||||
error: 'N Already Exist',
|
error: 'NPWP Already Exist',
|
||||||
},
|
},
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
|
@ -67,6 +69,69 @@ export class PartnerService {
|
||||||
return partnerData;
|
return partnerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async update(
|
||||||
|
id: string,
|
||||||
|
updatePartnerDto: UpdatePartnerDto,
|
||||||
|
currentUser: any,
|
||||||
|
) {
|
||||||
|
const check = await this.partnerRepository.findOne({
|
||||||
|
npwp: updatePartnerDto.npwp,
|
||||||
|
id: Not(id),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (check) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_ACCEPTABLE,
|
||||||
|
error: 'NPWP Already Exist',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const partnerData = new Partner();
|
||||||
|
|
||||||
|
partnerData.id = id;
|
||||||
|
partnerData.name = updatePartnerDto.name;
|
||||||
|
partnerData.address = updatePartnerDto.address;
|
||||||
|
|
||||||
|
if (updatePartnerDto.npwp) {
|
||||||
|
partnerData.npwp = updatePartnerDto.npwp;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.connection.transaction(async (manager) => {
|
||||||
|
await manager.update(Partner, { id: id }, partnerData);
|
||||||
|
});
|
||||||
|
|
||||||
|
const dataUser = new UpdateUserDto();
|
||||||
|
const userData = await this.userService.findOneByPartner(id);
|
||||||
|
|
||||||
|
dataUser.username = `admin_${partnerData.name}`;
|
||||||
|
dataUser.partner = partnerData;
|
||||||
|
|
||||||
|
await this.userService.update(userData.id, dataUser, currentUser);
|
||||||
|
|
||||||
|
return partnerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
setStatus = async (id: string, type: string) => {
|
||||||
|
const partnerData = await this.partnerRepository.findOne({
|
||||||
|
id: id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (type === 'active') {
|
||||||
|
partnerData.status = true;
|
||||||
|
} else {
|
||||||
|
partnerData.status = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.connection.transaction(async (manager) => {
|
||||||
|
await manager.update(Partner, { id: id }, partnerData);
|
||||||
|
});
|
||||||
|
|
||||||
|
return partnerData;
|
||||||
|
};
|
||||||
|
|
||||||
findAllPartner(page) {
|
findAllPartner(page) {
|
||||||
return this.partnerRepository.findAndCount({
|
return this.partnerRepository.findAndCount({
|
||||||
skip: page * 10,
|
skip: page * 10,
|
||||||
|
|
|
@ -6,13 +6,14 @@ import {
|
||||||
Injectable,
|
Injectable,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Connection, EntityNotFoundError, Repository } from 'typeorm';
|
import { Connection, EntityNotFoundError, Not, Repository } from 'typeorm';
|
||||||
import { Supplier } from '../entities/supplier.entity';
|
import { Supplier } from '../entities/supplier.entity';
|
||||||
import { InputCoaDto } from '../../transaction/dto/input-coa.dto';
|
import { InputCoaDto } from '../../transaction/dto/input-coa.dto';
|
||||||
import { balanceType, coaType } from '../../helper/enum-list';
|
import { balanceType, coaType } from '../../helper/enum-list';
|
||||||
import { CreateSupplierDto } from '../dto/create-supplier.dto';
|
import { CreateSupplierDto } from '../dto/create-supplier.dto';
|
||||||
import { CoaService } from '../../transaction/coa.service';
|
import { CoaService } from '../../transaction/coa.service';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
|
import { UpdateSupplierDto } from '../dto/update-supplier.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SupplierService {
|
export class SupplierService {
|
||||||
|
@ -84,6 +85,50 @@ export class SupplierService {
|
||||||
return supplierData;
|
return supplierData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async update(id: string, updateSupplierDto: UpdateSupplierDto) {
|
||||||
|
const check = await this.supplierRepository.findOne({
|
||||||
|
code: updateSupplierDto.code,
|
||||||
|
id: Not(id),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (check) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_ACCEPTABLE,
|
||||||
|
error: 'Supplier Already Exist',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const supplierData = new Supplier();
|
||||||
|
|
||||||
|
supplierData.name = updateSupplierDto.name;
|
||||||
|
supplierData.status = true;
|
||||||
|
|
||||||
|
await this.connection.transaction(async (manager) => {
|
||||||
|
await manager.update(Supplier, { id: id }, supplierData);
|
||||||
|
});
|
||||||
|
|
||||||
|
return supplierData;
|
||||||
|
}
|
||||||
|
|
||||||
|
setStatus = async (id: string, type: string) => {
|
||||||
|
const supplierData = new Supplier();
|
||||||
|
|
||||||
|
if (type === 'active') {
|
||||||
|
supplierData.status = true;
|
||||||
|
} else {
|
||||||
|
supplierData.status = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.connection.transaction(async (manager) => {
|
||||||
|
await manager.update(Supplier, { id: id }, supplierData);
|
||||||
|
});
|
||||||
|
|
||||||
|
return supplierData;
|
||||||
|
};
|
||||||
|
|
||||||
findAllSupplier(page) {
|
findAllSupplier(page) {
|
||||||
return this.supplierRepository.findAndCount({
|
return this.supplierRepository.findAndCount({
|
||||||
skip: page * 10,
|
skip: page * 10,
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import {
|
import {
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Body,
|
Body,
|
||||||
Put,
|
Controller,
|
||||||
Param,
|
|
||||||
Delete,
|
Delete,
|
||||||
ParseUUIDPipe,
|
Get,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
|
Param,
|
||||||
|
ParseUUIDPipe,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
Query,
|
Query,
|
||||||
Request,
|
Request,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
@ -19,6 +19,8 @@ import { CreateSupplierDto } from './dto/create-supplier.dto';
|
||||||
import { SupplierService } from './supplier/supplier.service';
|
import { SupplierService } from './supplier/supplier.service';
|
||||||
import { PartnerService } from './partner/partner.service';
|
import { PartnerService } from './partner/partner.service';
|
||||||
import { CreatePartnerDto } from './dto/create-partner.dto';
|
import { CreatePartnerDto } from './dto/create-partner.dto';
|
||||||
|
import { UpdatePartnerDto } from './dto/update-partner.dto';
|
||||||
|
import { UpdateSupplierDto } from './dto/update-supplier.dto';
|
||||||
|
|
||||||
@Controller({
|
@Controller({
|
||||||
path: 'users',
|
path: 'users',
|
||||||
|
@ -49,6 +51,30 @@ export class UsersController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('supplier/:id/:type')
|
||||||
|
async updateSupplier(
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@Param('type') type: string,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
data: await this.supplierService.setStatus(id, type),
|
||||||
|
statusCode: HttpStatus.CREATED,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('supplier/:id')
|
||||||
|
async setStatusSupplier(
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@Body() updatePartnerDto: UpdateSupplierDto,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
data: await this.supplierService.update(id, updatePartnerDto),
|
||||||
|
statusCode: HttpStatus.CREATED,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Post('partner')
|
@Post('partner')
|
||||||
async createPartner(
|
async createPartner(
|
||||||
@Request() req,
|
@Request() req,
|
||||||
|
@ -61,6 +87,31 @@ export class UsersController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('partner/:id/:type')
|
||||||
|
async setStatusPartner(
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@Param('type') type: string,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
data: await this.partnerService.setStatus(id, type),
|
||||||
|
statusCode: HttpStatus.CREATED,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('partner/:id')
|
||||||
|
async updatePartner(
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@Request() req,
|
||||||
|
@Body() updatePartnerDto: UpdatePartnerDto,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
data: await this.partnerService.update(id, updatePartnerDto, req.user),
|
||||||
|
statusCode: HttpStatus.CREATED,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll(@Request() req, @Query('page') page: number) {
|
async findAll(@Request() req, @Query('page') page: number) {
|
||||||
const [data, count] = await this.usersService.findAll(
|
const [data, count] = await this.usersService.findAll(
|
||||||
|
@ -140,13 +191,26 @@ export class UsersController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get(':id/:type')
|
||||||
|
async setStatusMembership(
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@Param('type') type: string,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
data: await this.usersService.setStatus(id, type),
|
||||||
|
statusCode: HttpStatus.CREATED,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
async update(
|
async update(
|
||||||
@Param('id', ParseUUIDPipe) id: string,
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@Request() req,
|
||||||
@Body() updateUserDto: UpdateUserDto,
|
@Body() updateUserDto: UpdateUserDto,
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
data: await this.usersService.update(id, updateUserDto),
|
data: await this.usersService.update(id, updateUserDto, req.user),
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.OK,
|
||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
|
|
|
@ -216,7 +216,7 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, updateUserDto: UpdateUserDto) {
|
async update(id: string, updateUserDto: UpdateUserDto, currentUser: any) {
|
||||||
try {
|
try {
|
||||||
await this.usersRepository.findOneOrFail(id);
|
await this.usersRepository.findOneOrFail(id);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -233,11 +233,50 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// const result = await this.usersRepository.update(id, updateUserDto);
|
const check = await this.usersRepository.findOne({
|
||||||
|
username: updateUserDto.username,
|
||||||
|
id: Not(id),
|
||||||
|
});
|
||||||
|
|
||||||
return this.usersRepository.findOneOrFail(id);
|
if (check) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_ACCEPTABLE,
|
||||||
|
error: 'Username Already Exist',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const userData = new User();
|
||||||
|
|
||||||
|
userData.id = id;
|
||||||
|
userData.username = updateUserDto.username;
|
||||||
|
userData.partner = updateUserDto.partner;
|
||||||
|
|
||||||
|
await this.connection.transaction(async (manager) => {
|
||||||
|
const result = await manager.update(User, { id: id }, userData);
|
||||||
|
});
|
||||||
|
|
||||||
|
return userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setStatus = async (id: string, type: string) => {
|
||||||
|
const userData = new User();
|
||||||
|
|
||||||
|
if (type === 'active') {
|
||||||
|
userData.isActive = true;
|
||||||
|
} else {
|
||||||
|
userData.isActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.connection.transaction(async (manager) => {
|
||||||
|
await manager.update(User, { id: id }, userData);
|
||||||
|
});
|
||||||
|
|
||||||
|
return userData;
|
||||||
|
};
|
||||||
|
|
||||||
async remove(id: string) {
|
async remove(id: string) {
|
||||||
try {
|
try {
|
||||||
await this.usersRepository.findOneOrFail(id);
|
await this.usersRepository.findOneOrFail(id);
|
||||||
|
@ -266,4 +305,27 @@ export class UsersService {
|
||||||
relations: ['roles', 'partner'],
|
relations: ['roles', 'partner'],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findOneByPartner(partnerId: string) {
|
||||||
|
try {
|
||||||
|
return this.usersRepository.findOneOrFail({
|
||||||
|
relations: ['roles'],
|
||||||
|
where: {
|
||||||
|
partner: partnerId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
error: 'Data not found',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
17
yarn.lock
17
yarn.lock
|
@ -4671,6 +4671,23 @@ pino@^7.0.5:
|
||||||
sonic-boom "^2.2.1"
|
sonic-boom "^2.2.1"
|
||||||
thread-stream "^0.13.0"
|
thread-stream "^0.13.0"
|
||||||
|
|
||||||
|
pino@^7.5.1:
|
||||||
|
version "7.5.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pino/-/pino-7.5.1.tgz#6e4cd3389e9365caf64039d4b83dcfa84ed43fee"
|
||||||
|
integrity sha512-Wzo2G7CLaRHKOz3+Ex006LC5Xi0xEUm+mwm/h0NKzuKZONdekcbmjXg7vWDoO8hVTGX+1RuUy2fwlzvZ24EI5A==
|
||||||
|
dependencies:
|
||||||
|
fast-redact "^3.0.0"
|
||||||
|
fastify-warning "^0.2.0"
|
||||||
|
get-caller-file "^2.0.5"
|
||||||
|
on-exit-leak-free "^0.2.0"
|
||||||
|
pino-abstract-transport v0.5.0
|
||||||
|
pino-std-serializers "^4.0.0"
|
||||||
|
quick-format-unescaped "^4.0.3"
|
||||||
|
real-require "^0.1.0"
|
||||||
|
safe-stable-stringify "^2.1.0"
|
||||||
|
sonic-boom "^2.2.1"
|
||||||
|
thread-stream "^0.13.0"
|
||||||
|
|
||||||
pirates@^4.0.1:
|
pirates@^4.0.1:
|
||||||
version "4.0.1"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.1.tgz#643a92caf894566f91b2b986d2c66950a8e2fb87"
|
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.1.tgz#643a92caf894566f91b2b986d2c66950a8e2fb87"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user