cityssm/lottery-licence-manager

View on GitHub
handlers/licences-post/doSave.js

Summary

Maintainability
A
2 hrs
Test Coverage
F
18%
import { createLicence } from "../../helpers/licencesDB/createLicence.js";
import { updateLicence } from "../../helpers/licencesDB/updateLicence.js";
export const handler = (request, response) => {
    if (request.body.licenceID === "") {
        const newLicenceID = createLicence(request.body, request.session);
        response.json({
            success: true,
            licenceID: newLicenceID
        });
    }
    else {
        const changeCount = updateLicence(request.body, request.session);
        if (changeCount) {
            response.json({
                success: true,
                message: "Licence updated successfully."
            });
        }
        else {
            response.json({
                success: false,
                message: "Record Not Saved"
            });
        }
    }
};
export default handler;