Skip to content

Commit e8eb3be

Browse files
author
shawon-majid
committed
seed updated and logout logging implemented
1 parent 1a80b2d commit e8eb3be

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

server/src/controllers/auth.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Request, Response } from "express";
22
import errorWrapper from "../middlewares/errorWrapper";
3-
import { PrismaClient, User } from "@prisma/client";
3+
import { PrismaClient } from "@prisma/client";
44
import bcrypt from "bcrypt";
55
import {
66
generateToken,
@@ -212,6 +212,19 @@ const logout = errorWrapper(
212212
const token = getToken(req) || "no token";
213213
invalidateToken(token);
214214
console.log("Logged Out Successfully");
215+
216+
if (req.user?.roleName === RoleName.CONTRACTOR_EMPLOYEE) {
217+
await contractorLog(
218+
`Logout`,
219+
`User ${req.user.username}, Role: ${req.user.roleName} logged out`
220+
);
221+
}
222+
223+
await adminLog(
224+
`Logout`,
225+
`User ${req.user?.username}, Role: ${req.user?.roleName} logged out`
226+
);
227+
215228
res.json({ msg: "Logged Out Successfully" });
216229
},
217230
{ statusCode: 500, message: `Logout Failed` }

server/src/prisma/seed.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -280,26 +280,6 @@ const userData: Prisma.UserCreateInput[] = [
280280
},
281281
];
282282

283-
const contractorData: Prisma.ContractorCreateInput[] = [
284-
{
285-
name: "Contractor 2 Name",
286-
registrationId: "ABSDC123456",
287-
registrationDate: "2024-05-10T00:00:00Z",
288-
tinNumber: "34334",
289-
contactNumber: "+929323",
290-
workforceSize: 100,
291-
paymentPerTon: 10.5,
292-
requiredWastePerDay: 500.0,
293-
contractDuration: "1 year",
294-
area: "City XYZ",
295-
assignedSTS: {
296-
connect: {
297-
id: "sts1",
298-
},
299-
},
300-
},
301-
];
302-
303283
const vehicleData: Prisma.VehicleCreateInput[] = [
304284
{
305285
id: "vid1",
@@ -550,6 +530,26 @@ const tripData: Prisma.TripCreateInput[] = [
550530
},
551531
];
552532

533+
const contractorData: Prisma.ContractorCreateInput[] = [
534+
{
535+
name: "Contractor 2 Name",
536+
registrationId: "ABSDC123456",
537+
registrationDate: "2024-05-10T00:00:00Z",
538+
tinNumber: "34334",
539+
contactNumber: "+929323",
540+
workforceSize: 100,
541+
paymentPerTon: 10.5,
542+
requiredWastePerDay: 500.0,
543+
contractDuration: "1 year",
544+
area: "City XYZ",
545+
assignedSTS: {
546+
connect: {
547+
id: "sts1",
548+
},
549+
},
550+
},
551+
];
552+
553553
async function main() {
554554
console.log("Seeding roles...");
555555
for (const role of roleData) {
@@ -599,14 +599,6 @@ async function main() {
599599
console.log(newRoute);
600600
}
601601

602-
console.log("Seeding contractors...");
603-
for (const contractor of contractorData) {
604-
const newContractor = await prisma.contractor.create({
605-
data: contractor,
606-
});
607-
console.log(newContractor);
608-
}
609-
610602
console.log("Seeding users...");
611603
for (const user of userData) {
612604
const newUser = await prisma.user.create({
@@ -655,6 +647,14 @@ async function main() {
655647
console.log(newTrip);
656648
}
657649

650+
console.log("Seeding contractors...");
651+
for (const contractor of contractorData) {
652+
const newContractor = await prisma.contractor.create({
653+
data: contractor,
654+
});
655+
console.log(newContractor);
656+
}
657+
658658
console.log("Seeding completed!");
659659
}
660660

0 commit comments

Comments
 (0)