Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Service
- const FormData = require('form-data');
- async scanBarcode(file: Express.Multer.File, body: { masa: string, tahun: string, iscreditable: string, upload: string }){
- try {
- const ortaxToken = await this.prisma.configGeneral.findFirst({
- where: {
- name: 'ortax_token',
- },
- });
- const ortaxXToken = await this.prisma.configGeneral.findFirst({
- where: {
- name: 'ortax_x_token',
- },
- });
- const formData = new FormData();
- formData.append('file', file.buffer, { filename: file.originalname });
- formData.append('masa', body.masa);
- formData.append('tahun', body.tahun);
- formData.append('iscreditable', body.iscreditable);
- formData.append('upload', body.upload);
- const url = `https://restdev.pajakexpress.com:9001/efaktur/pm/barcodefile`;
- const headers = {
- 'x-token': ortaxXToken.value,
- Authorization: `Bearer ${ortaxToken.value}`,
- ...formData.getHeaders(),
- };
- const response = await axios.post(url, formData, { headers });
- return response.data;
- } catch (error) {
- throw error;
- }
- }
- Controller
- import { FileInterceptor } from '@nestjs/platform-express';
- @Post('/efaktur/pm/barcodefile')
- @UseInterceptors(FileInterceptor('file'))
- async uploadFile(
- @UploadedFile() file: Express.Multer.File,
- @Body() body: { masa: string, tahun: string, iscreditable: string, upload: string }
- ){
- const data = await this.ortaxService.scanBarcode(file, body);
- return{
- data,
- statusCode: HttpStatus.OK,
- message: 'success',
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement