230 lines
7.7 KiB
JavaScript
230 lines
7.7 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.router = void 0;
|
|
const express_1 = require("express");
|
|
const express_validator_1 = require("express-validator");
|
|
const tindakan_service_1 = require("./tindakan.service");
|
|
exports.router = (0, express_1.Router)();
|
|
exports.router.get("/tindakan_id/:tindakan_id", (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
try {
|
|
const errors = (0, express_validator_1.validationResult)(req);
|
|
if (!errors.isEmpty()) {
|
|
res.status(200).send({
|
|
response: errors.array(),
|
|
metadata: {
|
|
code: 400,
|
|
message: "Validation error",
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
const tindakan_id = parseInt(req.params.tindakan_id, 10);
|
|
const getTindakan = yield (0, tindakan_service_1.getTindakanId)(tindakan_id);
|
|
if (getTindakan) {
|
|
res.status(200).send({
|
|
metadata: {
|
|
code: 200,
|
|
message: "Success",
|
|
},
|
|
response: getTindakan,
|
|
});
|
|
}
|
|
else {
|
|
res.status(200).send({
|
|
metadata: {
|
|
code: 201,
|
|
message: "Failed",
|
|
},
|
|
response: [],
|
|
});
|
|
}
|
|
}
|
|
catch (error) {
|
|
next(error.message.replace(/\n/g, " "));
|
|
}
|
|
}));
|
|
exports.router.get("/", (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
try {
|
|
const errors = (0, express_validator_1.validationResult)(req);
|
|
if (!errors.isEmpty()) {
|
|
res.status(200).send({
|
|
response: errors.array(),
|
|
metadata: {
|
|
code: 400,
|
|
message: "Validation error",
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
const getTindakan = yield (0, tindakan_service_1.getTindakanAll)();
|
|
if (getTindakan && getTindakan.length > 0) {
|
|
res.status(200).send({
|
|
metadata: {
|
|
code: 200,
|
|
message: "Success",
|
|
},
|
|
response: getTindakan,
|
|
});
|
|
}
|
|
else {
|
|
res.status(200).send({
|
|
metadata: {
|
|
code: 201,
|
|
message: "Failed",
|
|
},
|
|
response: [],
|
|
});
|
|
}
|
|
}
|
|
catch (error) {
|
|
next(error.message.replace(/\n/g, " "));
|
|
}
|
|
}));
|
|
exports.router.post("/", [
|
|
(0, express_validator_1.body)("namatindakan").notEmpty(),
|
|
(0, express_validator_1.body)("tariftindakan").notEmpty().isNumeric(),
|
|
], (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
try {
|
|
const errors = (0, express_validator_1.validationResult)(req);
|
|
if (!errors.isEmpty()) {
|
|
res.status(200).send({
|
|
response: errors.array(),
|
|
metadata: {
|
|
code: 400,
|
|
message: "Validation error",
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
const createTindakan = yield (0, tindakan_service_1.createTindakanData)(req.body);
|
|
if (createTindakan) {
|
|
res.status(200).send({
|
|
metadata: {
|
|
code: 200,
|
|
message: "Success",
|
|
},
|
|
response: createTindakan,
|
|
});
|
|
}
|
|
else {
|
|
res.status(200).send({
|
|
metadata: {
|
|
code: 201,
|
|
message: "Failed",
|
|
},
|
|
response: [],
|
|
});
|
|
}
|
|
}
|
|
catch (error) {
|
|
next(error.message.replace(/\n/g, " "));
|
|
}
|
|
}));
|
|
exports.router.put("/tindakan_id/:tindakan_id", [
|
|
(0, express_validator_1.param)("tindakan_id")
|
|
.notEmpty()
|
|
.custom((value, { req }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
value = parseInt(value, 10);
|
|
const tindakan_id = yield (0, tindakan_service_1.getTindakanId)(value);
|
|
if (!tindakan_id) {
|
|
return Promise.reject("Tindakan tidak ditemukan, silahkan coba lagi");
|
|
}
|
|
})),
|
|
(0, express_validator_1.body)("namatindakan").notEmpty(),
|
|
(0, express_validator_1.body)("tariftindakan").notEmpty().isNumeric(),
|
|
], (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
try {
|
|
const errors = (0, express_validator_1.validationResult)(req);
|
|
if (!errors.isEmpty()) {
|
|
res.status(200).send({
|
|
response: errors.array(),
|
|
metadata: {
|
|
code: 400,
|
|
message: "Validation error",
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
const tindakan_id = parseInt(req.params.tindakan_id, 10);
|
|
const updateTindakanAll = yield (0, tindakan_service_1.updateTindakanDataAll)(req.body, tindakan_id);
|
|
if (updateTindakanAll) {
|
|
res.status(200).send({
|
|
metadata: {
|
|
code: 200,
|
|
message: "Success",
|
|
},
|
|
response: updateTindakanAll,
|
|
});
|
|
}
|
|
else {
|
|
res.status(200).send({
|
|
metadata: {
|
|
code: 201,
|
|
message: "Failed",
|
|
},
|
|
response: [],
|
|
});
|
|
}
|
|
}
|
|
catch (error) {
|
|
next(error.message.replace(/\n/g, " "));
|
|
}
|
|
}));
|
|
exports.router.delete("/tindakan_id/:tindakan_id", [
|
|
(0, express_validator_1.param)("tindakan_id")
|
|
.notEmpty()
|
|
.custom((value, { req }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
value = parseInt(value, 10);
|
|
const TindakanId = yield (0, tindakan_service_1.getTindakanId)(value);
|
|
if (!TindakanId) {
|
|
return Promise.reject("Tindakan ID tidak ditemukan, silahkan coba lagi");
|
|
}
|
|
})),
|
|
], (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
try {
|
|
const errors = (0, express_validator_1.validationResult)(req);
|
|
if (!errors.isEmpty()) {
|
|
res.status(200).send({
|
|
response: errors.array(),
|
|
metadata: {
|
|
code: 400,
|
|
message: "Validation error",
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
const tindakan_id = parseInt(req.params.tindakan_id, 10);
|
|
const deleteTindakan = yield (0, tindakan_service_1.deleteTindakanData)(tindakan_id);
|
|
if (deleteTindakan) {
|
|
res.status(200).send({
|
|
metadata: {
|
|
code: 200,
|
|
message: "Success",
|
|
},
|
|
response: deleteTindakan,
|
|
});
|
|
}
|
|
else {
|
|
res.status(200).send({
|
|
metadata: {
|
|
code: 201,
|
|
message: "Failed",
|
|
},
|
|
response: [],
|
|
});
|
|
}
|
|
}
|
|
catch (error) {
|
|
next(error.message.replace(/\n/g, " "));
|
|
}
|
|
}));
|