feat(certificate): update certificate tag format
This commit is contained in:
@@ -101,6 +101,12 @@ class CertificateRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async countByProject(id_project) {
|
||||||
|
return prisma.certificate.count({
|
||||||
|
where: { id_project: parseInt(id_project) },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async updateProjectTemplate(id_project, templatePath) {
|
async updateProjectTemplate(id_project, templatePath) {
|
||||||
return prisma.project.update({
|
return prisma.project.update({
|
||||||
where: { id: parseInt(id_project) },
|
where: { id: parseInt(id_project) },
|
||||||
|
|||||||
@@ -57,13 +57,15 @@ class CertificateService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate certificate number berdsarkan format ini: CERT/YYYYMMDD/PRJ{id_project}/USR{id_user} [Rafi 09/06/2026 20:45]
|
// Generate certificate number berdsarkan format ini: CERT/YYYYMMDD/{count} [Rafi 12/07/2026 14:32]
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const year = now.getFullYear();
|
const year = String(now.getFullYear()).slice(-2);
|
||||||
|
const day = String(now.getDate()).padStart(2, '0');
|
||||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||||
const date = String(now.getDate()).padStart(2, '0');
|
const dateString = `${year}${day}${month}`;
|
||||||
const dateString = `${year}${month}${date}`;
|
|
||||||
const certificateNo = `CERT/${dateString}/PRJ${id_project}/USR${actor.id}`;
|
const count = await certificateRepository.countByProject(id_project);
|
||||||
|
const certificateNo = `CERT/${dateString}/${count + 1}`;
|
||||||
|
|
||||||
const certificateData = {
|
const certificateData = {
|
||||||
id_project: parseInt(id_project),
|
id_project: parseInt(id_project),
|
||||||
@@ -149,13 +151,16 @@ class CertificateService {
|
|||||||
|
|
||||||
const generatedCertificates = [];
|
const generatedCertificates = [];
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const year = now.getFullYear();
|
const year = String(now.getFullYear()).slice(-2);
|
||||||
|
const day = String(now.getDate()).padStart(2, '0');
|
||||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||||
const date = String(now.getDate()).padStart(2, '0');
|
const dateString = `${year}${day}${month}`;
|
||||||
const dateString = `${year}${month}${date}`;
|
|
||||||
|
let currentCount = await certificateRepository.countByProject(id_project);
|
||||||
|
|
||||||
for (const userId of validatedUsers) {
|
for (const userId of validatedUsers) {
|
||||||
const certificateNo = `CERT/${dateString}/PRJ${id_project}/USR${userId}`;
|
currentCount++;
|
||||||
|
const certificateNo = `CERT/${dateString}/${currentCount}`;
|
||||||
const certificateData = {
|
const certificateData = {
|
||||||
id_project: parseInt(id_project),
|
id_project: parseInt(id_project),
|
||||||
id_user: parseInt(userId),
|
id_user: parseInt(userId),
|
||||||
|
|||||||
Reference in New Issue
Block a user