feat: add change status partner endpoint

This commit is contained in:
caturbgs 2021-12-14 16:03:59 +07:00
parent 6b1352e671
commit 04fd5c571f
2 changed files with 37 additions and 1 deletions

View File

@ -1,4 +1,10 @@
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import {
forwardRef,
HttpException,
HttpStatus,
Inject,
Injectable,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Connection, Not, Repository } from 'typeorm';
import { CoaService } from '../../transaction/coa.service';
@ -108,6 +114,24 @@ export class PartnerService {
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) {
return this.partnerRepository.findAndCount({
skip: page * 10,

View File

@ -62,6 +62,18 @@ 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,