This commit is contained in:
root
2026-01-07 14:03:34 +09:00
commit 4e93d0a49c
149 changed files with 20897 additions and 0 deletions

36
middlewares/auth.js Normal file
View File

@ -0,0 +1,36 @@
const jwt = require('jsonwebtoken');
module.exports = (req, res, next) => {
// console.log(req);
const authheader = req.get("Authorization");
// console.log(authheader);
if(!authheader){
const error = new Error("Not Authenticated");
error.statusCode = 401;
throw error;
}
const token = authheader.split(" ")[1];
// console.log(token);
let decodedtoken;
try {
// decodedtoken = jwt.verify(token, process.env.SECRET_KEY);
decodedtoken = jwt.verify(token, "Pr0C#2022oct");
req.nik = decodedtoken.nik;
// console.log(decodedtoken);
} catch (error) {
// console.log("fdfdf "+error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
if(!decodedtoken){
const error = new Error("Not Authenticated");
error.statusCode = 401;
throw error;
}
next();
}

96
middlewares/logging.js Normal file
View File

@ -0,0 +1,96 @@
const colllogging = require('../models/colllogging');
// const getLoggerForStatusCode = (statusCode) => {
// // console.log(statusCode);
// if (statusCode >= 500) {
// return console.error.bind(console)
// }
// if (statusCode >= 400) {
// return console.warn.bind(console)
// }
// return console.log.bind(console)
// }
module.exports = (req, res, next) => {
// console.info(`${req.method} ${req.originalUrl}`)
const cleanup = () => {
res.removeListener('finish', logFn)
res.removeListener('close', abortFn)
res.removeListener('error', errorFn)
}
const logFn = () => {
try {
cleanup()
// console.log(req['headers']['content-type'])
let nz_date_string = new Date().toLocaleString("en-US", { timeZone: "Asia/Jakarta" });
// console.log(nz_date_string);
// const secretkey = req.body.secretkey
const iprequest = req.headers['x-forwarded-for']
const timestamp = nz_date_string//new Date().toISOString()
const useragent = req.headers['user-agent']
const contenttype = req.headers['content-type']==undefined ? "none" : req.headers['content-type']
const originalurl = req.originalUrl
const requestbody = JSON.stringify(req.body)
const requestheader = JSON.stringify(req.headers)
const statuscode = res.statusCode
const response = res.get('responseData')
var savelogging = new colllogging(
{
// secretkey : secretkey,
iprequest : iprequest,
timestamp : timestamp,
useragent : useragent,
contenttype : contenttype,
originalurl : originalurl,
requestbody : requestbody,
requestheader : requestheader,
statuscode : statuscode,
response : response
}
);
savelogging.save(function(err,data){
if(err)
{
const error = new Error("Logging failed");
error.statusCode = 401;
error.message = err.toString();
throw error;
}
else{
//console.log(data);
}
});
} catch (err) {
const error = new Error("Logging failed");
error.statusCode = 401;
error.message = err.toString();
throw error;
}
}
const abortFn = () => {
cleanup()
console.warn('Request aborted by the client')
}
const errorFn = err => {
cleanup()
console.error(`Request pipeline error: ${err}`)
}
// successful pipeline (regardless of its response)
res.on('finish', logFn) // successful pipeline (regardless of its response)
res.on('close', abortFn) // aborted pipeline
res.on('error', errorFn) // pipeline internal error
next()
}

61
middlewares/multer.js Normal file
View File

@ -0,0 +1,61 @@
const multer = require('multer');
const path = require('path');
const imageStorage = multer.diskStorage({
// Destination to store image
destination: 'assets/images',
filename: (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
// cb(null, filename + '_' + Date.now() + path.extname(file.originalname))
cb(null, file.originalname)
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
const imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: 1500000 // 1000000 Bytes = 1 MB
},
fileFilter(req, file, cb) {
if (!file.originalname.match(/\.(png|jpg)$/)) {
// upload only png and jpg format
return cb(new Error('Please upload a Image'))
}
// cb(undefined, true)
cb(null, true)
}
}).single("attendancefile");
module.exports = (req, res, next) => {
try {
// console.log(req);
imageUpload(req,res,next, function(err){
try {
if (err){
console.log(err);
res.status(400).send({
"success":false,
"message" : JSON.stringify(err),
"data" :[]
});
} else {
console.log('The filename is ' + res.req.file.filename);
// req.append("filename",res.req.file.filename);
// req.body.attendancefile=res.req.file.filename;
}
next();
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log(error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}

View File

@ -0,0 +1,79 @@
const multer = require('multer');
const path = require('path');
var imageStorage = multer.diskStorage({
// Destination to store image
// destination: 'assets/images/'+pathDir,
destination: (req, file, cb) => {
// console.log(req.get("path"));
// let pathdir = req.get("path");
cb(null, "assets/po/")
// cb(null, "assets/words/" + pathdir + "/")
},
filename : (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
// console.log("body :"+req.body);
let nik = req.nik;
// let category = req.body.filecategory;
// let filedoc = category+'_'+nik+'_' + Date.now() + path.extname(file.originalname);
let filedoc = nik+'_' + Date.now() + path.extname(file.originalname);
// req.body.filedoc = filedoc;
// cb(null, filedoc);
// console.log(filedoc);
req.body.filename = filedoc;
cb(null, filedoc)
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
var imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: '5mb' // 1000000 Bytes = 5 MB
},
fileFilter(req, file, cb) {
// if (!file.originalname.match(/\.(png|jpg|pdf)$/)) {
// console.log(file.originalname.match);
if (!file.originalname.match(/\.(docx|pdf|PDF)$/)) {
// upload only png and jpg format
req.fileValidationError = "Please upload a word document in ( docx / pdf ) max 5 mb";
cb(new Error('Please upload a word document in ( docx / pdf ) max 5 mb'), false);
}
else{
cb(null, true);
}
}
}).single("file-doc");
module.exports = (req, res, next) => {
try {
imageUpload(req,res, function(err){
try {
// if (err || err instanceof multer.MulterError){
if (err){
res.status(500).send({
"meta":{
"auth": false,
"code" : 500,
"message" : req.fileValidationError || err.toString(),
},
"data" :[]
});
} else {
next();
// console.log('The filename is ' + res.req.file.filename);
}
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log("error " + error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}

View File

@ -0,0 +1,79 @@
const multer = require('multer');
const path = require('path');
var imageStorage = multer.diskStorage({
// Destination to store image
// destination: 'assets/images/'+pathDir,
destination: (req, file, cb) => {
// console.log(req.get("path"));
// let pathdir = req.get("path");
cb(null, "assets/po/boq")
// cb(null, "assets/words/" + pathdir + "/")
},
filename : (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
// console.log("body :"+req.body);
let nik = req.nik;
// let category = req.body.filecategory;
// let filedoc = category+'_'+nik+'_' + Date.now() + path.extname(file.originalname);
let filedoc = nik+'_boq' + path.extname(file.originalname);
// req.body.filedoc = filedoc;
// cb(null, filedoc);
// console.log(filedoc);
req.body.filename = filedoc;
cb(null, filedoc)
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
var imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: '5mb' // 1000000 Bytes = 5 MB
},
fileFilter(req, file, cb) {
// if (!file.originalname.match(/\.(png|jpg|pdf)$/)) {
// console.log(file.originalname.match);
if (!file.originalname.match(/\.(csv)$/)) {
// upload only png and jpg format
req.fileValidationError = "Please upload a word document in ( csv ) max 5 mb";
cb(new Error('Please upload a csv file format max 5 mb'), false);
}
else{
cb(null, true);
}
}
}).single("file-doc");
module.exports = (req, res, next) => {
try {
imageUpload(req,res, function(err){
try {
// if (err || err instanceof multer.MulterError){
if (err){
res.status(500).send({
"meta":{
"auth": false,
"code" : 500,
"message" : req.fileValidationError || err.toString(),
},
"data" :[]
});
} else {
next();
// console.log('The filename is ' + res.req.file.filename);
}
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log("error " + error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}

View File

@ -0,0 +1,77 @@
const multer = require('multer');
const path = require('path');
var imageStorage = multer.diskStorage({
// Destination to store image
// destination: 'assets/images/'+pathDir,
destination: (req, file, cb) => {
// console.log(req.get("path"));
// let pathdir = req.get("path");
cb(null, "assets/procjustification/")
// cb(null, "assets/words/" + pathdir + "/")
},
filename : (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
// console.log("body :"+req.body);
let nik = req.nik;
// let category = req.body.filecategory;
// let filedoc = category+'_'+nik+'_' + Date.now() + path.extname(file.originalname);
let filedoc = nik+'_' + Date.now() + path.extname(file.originalname);
// req.body.filedoc = filedoc;
// cb(null, filedoc);
req.body.filename = filedoc;
cb(null, filedoc)
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
var imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: '5mb' // 1000000 Bytes = 5 MB
},
fileFilter(req, file, cb) {
// if (!file.originalname.match(/\.(png|jpg|pdf)$/)) {
if (!file.originalname.match(/\.(docx|pdf)$/)) {
// upload only png and jpg format
req.fileValidationError = "Please upload a word document in ( docx / pdf ) max 5 mb";
cb(new Error('Please upload a word document in ( docx / pdf ) max 5 mb'), false);
}
else{
cb(null, true);
}
}
}).single("file-doc");
module.exports = (req, res, next) => {
try {
imageUpload(req,res, function(err){
try {
// if (err || err instanceof multer.MulterError){
if (err){
res.status(500).send({
"meta":{
"auth": false,
"code" : 500,
"message" : req.fileValidationError || err.toString(),
},
"data" :[]
});
} else {
next();
// console.log('The filename is ' + res.req.file.filename);
}
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log("error " + error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}

View File

@ -0,0 +1,74 @@
const multer = require('multer');
const path = require('path');
var imageStorage = multer.diskStorage({
// Destination to store image
// destination: 'assets/images/'+pathDir,
destination: (req, file, cb) => {
// console.log(req.get("path"));
// let pathdir = req.get("path");
cb(null, "assets/words/")
// cb(null, "assets/words/" + pathdir + "/")
},
filename : (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
let nik = req.nik;
let filedoc = 'justifikasi_'+nik+'_' + Date.now() + path.extname(file.originalname);
// req.body.filedoc = filedoc;
// cb(null, filedoc);
req.body.filename = filedoc;
cb(null, filedoc)
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
var imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: '5mb' // 1000000 Bytes = 5 MB
},
fileFilter(req, file, cb) {
// if (!file.originalname.match(/\.(png|jpg|pdf)$/)) {
if (!file.originalname.match(/\.(docx)$/)) {
// upload only png and jpg format
req.fileValidationError = "Please upload a word document in ( docx ) max 5 mb";
cb(new Error('Please upload a word document in ( docx ) max 5 mb'), false);
}
else{
cb(null, true);
}
}
}).single("file-doc");
module.exports = (req, res, next) => {
try {
imageUpload(req,res, function(err){
try {
// if (err || err instanceof multer.MulterError){
if (err){
res.status(500).send({
"meta":{
"auth": false,
"code" : 500,
"message" : req.fileValidationError || err.toString(),
},
"data" :[]
});
} else {
next();
// console.log('The filename is ' + res.req.file.filename);
}
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log("error " + error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}

View File

@ -0,0 +1,75 @@
const multer = require('multer');
const path = require('path');
var imageStorage = multer.diskStorage({
// Destination to store image
// destination: 'assets/images/'+pathDir,
destination: (req, file, cb) => {
// console.log(req.get("path"));
// let pathdir = req.get("path");
cb(null, "assets/bast/pdf/")
// cb(null, "assets/words/" + pathdir + "/")
},
filename : (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
let nik = req.nik;
let filedoc = 'bast_'+nik+'_' + Date.now() + path.extname(file.originalname);
// req.body.filedoc = filedoc;
// cb(null, filedoc);
req.body.filename = filedoc;
cb(null, filedoc);
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
var imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: '5mb' // 1000000 Bytes = 5 MB
},
fileFilter(req, file, cb) {
// if (!file.originalname.match(/\.(png|jpg|pdf)$/)) {
// if (!file.originalname.match(/\.(docx|pdf)$/)) {
if (!file.originalname.match(/\.(pdf)$/)) {
// upload only png and jpg format
req.fileValidationError = "Please upload a word document in ( docx ) max 5 mb";
cb(new Error('Please upload a word document in ( docx ) max 5 mb'), false);
}
else{
cb(null, true);
}
}
}).single("file-doc");
module.exports = (req, res, next) => {
try {
imageUpload(req,res, function(err){
try {
// if (err || err instanceof multer.MulterError){
if (err){
res.status(500).send({
"meta":{
"auth": false,
"code" : 500,
"message" : req.fileValidationError || err.toString(),
},
"data" :[]
});
} else {
next();
// console.log('The filename is ' + res.req.file.filename);
}
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log("error " + error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}

View File

@ -0,0 +1,74 @@
const multer = require('multer');
const path = require('path');
var imageStorage = multer.diskStorage({
// Destination to store image
// destination: 'assets/images/'+pathDir,
destination: (req, file, cb) => {
// console.log(req.get("path"));
// let pathdir = req.get("path");
cb(null, "assets/finance/")
// cb(null, "assets/words/" + pathdir + "/")
},
filename : (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
let nik = req.nik;
let filedoc = 'fin_'+nik+'_' + Date.now() + path.extname(file.originalname);
// req.body.filedoc = filedoc;
// cb(null, filedoc);
req.body.filename = filedoc;
cb(null, filedoc);
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
var imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: '5mb' // 1000000 Bytes = 5 MB
},
fileFilter(req, file, cb) {
// if (!file.originalname.match(/\.(png|jpg|pdf)$/)) {
if (!file.originalname.match(/\.(docx|pdf)$/)) {
// upload only png and jpg format
req.fileValidationError = "Please upload a word document in ( docx / pdf ) max 5 mb";
cb(new Error('Please upload a word document in ( docx / pdf ) max 5 mb'), false);
}
else{
cb(null, true);
}
}
}).single("file-doc");
module.exports = (req, res, next) => {
try {
imageUpload(req,res, function(err){
try {
// if (err || err instanceof multer.MulterError){
if (err){
res.status(500).send({
"meta":{
"auth": false,
"code" : 500,
"message" : req.fileValidationError || err.toString(),
},
"data" :[]
});
} else {
next();
// console.log('The filename is ' + res.req.file.filename);
}
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log("error " + error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}

View File

@ -0,0 +1,74 @@
const multer = require('multer');
const path = require('path');
var imageStorage = multer.diskStorage({
// Destination to store image
// destination: 'assets/images/'+pathDir,
destination: (req, file, cb) => {
// console.log(req.get("path"));
// let pathdir = req.get("path");
cb(null, "assets/bast/")
// cb(null, "assets/words/" + pathdir + "/")
},
filename : (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
let nik = req.nik;
let filedoc = 'basthandover_'+nik+'_' + Date.now() + path.extname(file.originalname);
// req.body.filedoc = filedoc;
// cb(null, filedoc);
req.body.filename = filedoc;
cb(null, filedoc);
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
var imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: '5mb' // 1000000 Bytes = 5 MB
},
fileFilter(req, file, cb) {
if (!file.originalname.match(/\.(docx|pdf|PDF)$/)) {
// if (!file.originalname.match(/\.(docx)$/)) {
// upload only png and jpg format
req.fileValidationError = "Please upload a word document in ( docx ) / pdf file max 5 mb";
cb(new Error('Please upload a word document in ( docx ) / pdf file max 5 mb'), false);
}
else{
cb(null, true);
}
}
}).single("file-doc");
module.exports = (req, res, next) => {
try {
imageUpload(req,res, function(err){
try {
// if (err || err instanceof multer.MulterError){
if (err){
res.status(500).send({
"meta":{
"auth": false,
"code" : 500,
"message" : req.fileValidationError || err.toString(),
},
"data" :[]
});
} else {
next();
// console.log('The filename is ' + res.req.file.filename);
}
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log("error " + error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}

View File

@ -0,0 +1,74 @@
const multer = require('multer');
const path = require('path');
var imageStorage = multer.diskStorage({
// Destination to store image
// destination: 'assets/images/'+pathDir,
destination: (req, file, cb) => {
// console.log(req.get("path"));
// let pathdir = req.get("path");
cb(null, "assets/bast/")
// cb(null, "assets/words/" + pathdir + "/")
},
filename : (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
let nik = req.nik;
let filedoc = 'basthandoversign_'+nik+'_' + Date.now() + path.extname(file.originalname);
// req.body.filedoc = filedoc;
// cb(null, filedoc);
req.body.filename = filedoc;
cb(null, filedoc);
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
var imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: '5mb' // 1000000 Bytes = 5 MB
},
fileFilter(req, file, cb) {
if (!file.originalname.match(/\.(docx|pdf|PDF)$/)) {
// if (!file.originalname.match(/\.(docx)$/)) {
// upload only png and jpg format
req.fileValidationError = "Please upload a word document in ( docx ) / pdf file max 5 mb";
cb(new Error('Please upload a word document in ( docx ) / pdf file max 5 mb'), false);
}
else{
cb(null, true);
}
}
}).single("file-doc");
module.exports = (req, res, next) => {
try {
imageUpload(req,res, function(err){
try {
// if (err || err instanceof multer.MulterError){
if (err){
res.status(500).send({
"meta":{
"auth": false,
"code" : 500,
"message" : req.fileValidationError || err.toString(),
},
"data" :[]
});
} else {
next();
// console.log('The filename is ' + res.req.file.filename);
}
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log("error " + error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}

View File

@ -0,0 +1,76 @@
const multer = require('multer');
const path = require('path');
var imageStorage = multer.diskStorage({
// Destination to store image
// destination: 'assets/images/'+pathDir,
destination: (req, file, cb) => {
console.log('d');
// console.log(req.get("path"));
// let pathdir = req.get("path");
cb(null, "assets/justification/")
// cb(null, "assets/words/" + pathdir + "/")
},
filename : (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
console.log('filed');
let nik = req.nik;
let filedoc = 'justifikasi_'+nik+'_' + Date.now() + path.extname(file.originalname);
// req.body.filedoc = filedoc;
// cb(null, filedoc);
req.body.filename = filedoc;
cb(null, filedoc)
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
var imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: '5mb' // 1000000 Bytes = 5 MB
},
fileFilter(req, file, cb) {
// if (!file.originalname.match(/\.(png|jpg|pdf)$/)) {
if (!file.originalname.match(/\.(docx)$/)) {
// upload only png and jpg format
req.fileValidationError = "Please upload a word document in ( docx ) max 5 mb";
cb(new Error('Please upload a word document in ( docx ) max 5 mb'), false);
}
else{
cb(null, true);
}
}
}).single("file-doc");
module.exports = (req, res, next) => {
try {
imageUpload(req,res, function(err){
try {
// if (err || err instanceof multer.MulterError){
if (err){
res.status(500).send({
"meta":{
"auth": false,
"code" : 500,
"message" : req.fileValidationError || err.toString(),
},
"data" :[]
});
} else {
next();
// console.log('The filename is ' + res.req.file.filename);
}
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log("error " + error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}