Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express')
- const app = express.Router()
- const moment = require('moment')
- const transaction = require('../schema/transactionSchema')
- const transactionDetail = require('../schema/transactionDetailSchema')
- const product = require('../schema/productSchema')
- const purchase = require('../schema/tempPurchaseSchema')
- const mutation = require('../schema/mutationSchema')
- const {
- formatPrice, formatDate, toTitleCase, funcZero, funcDate, funcYear
- } = require('../config/formatData')
- // find all
- app.get('/findAll', async (req, res) => {
- try {
- let results = await transaction.all()
- res.status(200).json(results)
- }catch(e) {
- res.sendStatus(500)
- }
- })
- // find one transaction
- app.get('/findOne/:id', async (req, res) => {
- try{
- let response = await transaction.id(req.params.id)
- res.status(200).json( response )
- } catch(e) {
- res.sendStatus(500)
- }
- })
- app.get('/findAll/v2/last', async (req, res) => {
- try{
- let response = await transaction.last()
- res.status(200).json(response)
- } catch(e) {
- console.log(e)
- res.sendStatus(500)
- }
- })
- // insert table
- app.post('/added', async (req, res) => {
- try {
- let body = req.body
- let response = await transaction.add(
- body.id_transaction,
- body.id_user,
- body.id_supplier,
- body.trx_amount_paid,
- body.trx_amount_cutting,
- body.trx_amount_discount,
- body.trx_startDate_nota,
- body.trx_endDate_nota,
- body.trx_number_nota
- ) //inserrt data
- //insert to tb_temporary stock
- // get tb_temporary stock
- // // //insert into table product
- if (body.productList.length > 0) { //dataliost from react
- for(let items = body.productList.length -1; items >= 0; items--) {
- let results = await product.updateStock(
- body.productList[items].temp_id_product,
- body.productList[items].temp_id_type,
- body.productList[items].temp_id_brand,
- body.productList[items].temp_prod_name,
- body.productList[items].temp_prod_amount, //add stock to product
- body.productList[items].temp_prod_purchase, //search average
- body.productList[items].temp_prod_selling,
- body.productList[items].temp_prod_cutted,
- body.productList[items].temp_prod_discount
- )
- }
- }
- //insert to tb_mutation
- // //insert to tbl detail transaction
- // if (body.datalist.length > 0) { //dataliost from react
- // let response_d = 0;
- // for(let i = body.datalist.length -1; i >=0; i--) {
- // datas =
- // response_d = await transactionDetail.add(
- // body.id_transaction,
- // body.datalist[i].temp_id_product,
- // body.datalist[i].temp_prod_amount,
- // body.datalist[i].temp_prod_cutted,
- // body.datalist[i].temp_prod_discount,
- // )
- // }
- // }
- res.status(200).json(response)
- }catch(e) {
- console.log(e)
- res.sendStatus(500)
- }
- })
- // transaction updates
- app.put('/updated/:id', async (req, res) => {
- try{
- let id = req.params.id
- let x = req.body
- let results = await transaction.update(
- id,
- // x.id_transaction,
- x.id_user,
- x.id_supplier,
- x.trx_amount_paid,
- x.trx_amount_cutting
- )
- res.status(200).json( results )
- }catch(e) {
- console.log(e)
- res.sendStatus(500)
- }
- })
- // transaction delete
- app.delete('/removed/:id', async(req, res) => {
- try {
- let results = await transaction.remove(req.params.id)
- res.status(200).json(results)
- }catch(e) {
- res.sendStatus(500)
- }
- })
- module.exports = app;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement