agmission/Development/server/routes/log_payment.js

36 lines
1.4 KiB
JavaScript

const Joi = require("joi");
Joi.objectId = require('joi-objectid')(Joi)
const { validateInputRequest, authRoles } = require("../middlewares/validate");
const { PaymentMethod, jobInvoiceViewRoles, jobInvoiceEditRoles } = require("../helpers/constants");
module.exports = function (app) {
const router = require("express").Router(), logPaymentCtl = require("../controllers/log_payment");
// On routes that end in /log-payments
router.route("/")
.get(authRoles(jobInvoiceViewRoles), validateInputRequest(getLogPaymentsSchema), logPaymentCtl.getLogPayments_get)
.post(authRoles(jobInvoiceEditRoles), validateInputRequest(createLogPaymentSchema), logPaymentCtl.createLogPayment_post);
// On routes that end in /log-payments
router.route("/createLogPayments")
.post(authRoles(jobInvoiceEditRoles), validateInputRequest(createLogPaymentsSchema), logPaymentCtl.createLogPayments_post);
app.use("/api/logPayments", router);
};
const getLogPaymentsSchema = Joi.object({
invoiceId: Joi.objectId().required()
})
const createLogCommonDto = {
invoiceId: Joi.objectId().required(),
clientId: Joi.objectId().required(),
amount: Joi.string().required(),
paymentMethod: Joi.string().valid(...Object.values(PaymentMethod)).required(),
paymentDate: Joi.date().iso().required(),
}
const createLogPaymentSchema = Joi.object(createLogCommonDto);
const createLogPaymentsSchema = Joi.array().min(1).items(createLogCommonDto).required()