-
Notifications
You must be signed in to change notification settings - Fork 2
/
.idea
37 lines (35 loc) · 1.72 KB
/
.idea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
app.post("/post-data", upload.single("fileFoto"), (req, res) => {
// prettier-ignore
const { namaLengkap, NIS, NIS2, NISN, kelas, tempatLahir, tglLahir, blnLahir, thnLahir, alamat } = req.body;
// prettier-ignore
const programKeahlian = kelas == "Rekayasa Perangkat Lunak" ? "Teknik Informatika dan Komputer" : "Teknologi dan Rekayasa";
const data = {
nama: namaLengkap.toUpperCase(),
nomorInduk: `${NIS}/${NIS2} - ${NISN}`,
programKeahlian,
kompetensiKeahlian: kelas,
ttl: `${tempatLahir}, ${tglLahir} ${blnLahir} ${thnLahir}`,
tmpfoto: req.file,
alamat,
};
console.log(data);
// prettier-ignore
fs.renameSync(`./${data.tmpfoto.path.replace("\\", "/")}`, `./${data.tmpfoto.path.replace("\\", "/")}.jpeg`);
const foto = data.tmpfoto.filename + ".jpeg";
res.render("kartu", { data, foto });
});
app.post("/form/:kelas/add", upload.single("fileFoto"), (req, res) => {
const { kelas } = req.params;
const fileFoto = req.file;
const { namaLengkap, NIS, NIS2, NISN, komp_keahlian, tempatLahir, tglLahir, blnLahir, thnLahir, alamat } = req.body;
const ttl = `${tempatLahir}, ${tglLahir} ${blnLahir} ${thnLahir}`;
const fileBlob = fileFoto.buffer;
const fileName = fileFoto.originalname;
const foto = `/uploads/${kelas}/${fileName}`
if (!fs.existsSync(`./uploads/${kelas}`)) fs.mkdirSync(`./uploads/${kelas}`);
fs.writeFileSync(`./uploads/${kelas}/${fileName}`, fileBlob);
db.query(`INSERT INTO siswa(kelas, nama, nis, absen, nisn, komp_keahlian, ttl, alamat, foto) VALUES('${kelas}', '${namaLengkap}', '${NIS}', '${NIS2}', '${NISN}', '${komp_keahlian}', '${ttl}', '${alamat}', '${foto}')`, (err, result, field) => {
if (err) res.json(`Error : ${err}`);
res.json("Success!");
});
});