Skip to content

Commit e3e8458

Browse files
author
shawon-majid
committed
logs and employee api and schema update
1 parent 366541d commit e3e8458

File tree

11 files changed

+176
-7
lines changed

11 files changed

+176
-7
lines changed

server/.DS_Store

0 Bytes
Binary file not shown.

server/src/.DS_Store

0 Bytes
Binary file not shown.

server/src/controllers/auth.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,59 @@ const createManager = errorWrapper(
8989
{ statusCode: 500, message: `Couldn't create user` }
9090
);
9191

92+
const createEmployee = errorWrapper(
93+
async (req: Request, res: Response) => {
94+
const {
95+
username,
96+
password,
97+
email,
98+
roleName,
99+
contractorId,
100+
dateOfBirth,
101+
dateOfHire,
102+
jobTitle,
103+
paymentRatePerHour,
104+
routeId,
105+
} = req.body;
106+
const hashedPassword = await bcrypt.hash(password, 10);
107+
108+
const user = await prisma.user.create({
109+
data: {
110+
username,
111+
email,
112+
hashedPassword,
113+
roleName,
114+
dateOfBirth,
115+
dateOfHire,
116+
jobTitle,
117+
paymentRatePerHour,
118+
routeId,
119+
contractorId,
120+
},
121+
});
122+
123+
const token = generateToken(
124+
{
125+
id: user.id,
126+
role: user.roleName,
127+
},
128+
"10h"
129+
);
130+
131+
sendMail(
132+
user,
133+
`Welcome To EcoSync!`,
134+
`Your account has been created by Contractor Manager! Here are the Credentials:`,
135+
`username: ${username}<br>email: ${email}<br> password: ${password}<br><br>Regards,<br>EcoSync Team`
136+
);
137+
138+
await adminLog(`Employee Entry`, `Employee ${user.username} added`);
139+
140+
res.status(201).json({ user, token });
141+
},
142+
{ statusCode: 500, message: `Couldn't create user` }
143+
);
144+
92145
const login = errorWrapper(
93146
async (req: Request, res: Response) => {
94147
const { email, password } = req.body;
@@ -256,6 +309,7 @@ const resetPasswordConfirm = errorWrapper(
256309
export {
257310
createUser,
258311
createManager,
312+
createEmployee,
259313
login,
260314
logout,
261315
resetPasswordInit,

server/src/controllers/employee.ts

Whitespace-only changes.

server/src/controllers/logs.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// get all admin logs
2+
3+
import { PrismaClient } from "@prisma/client";
4+
import errorWrapper from "../middlewares/errorWrapper";
5+
import { Request, Response } from "express";
6+
7+
const prisma = new PrismaClient();
8+
9+
const getAdminLogs = errorWrapper(
10+
async (req: Request, res: Response) => {
11+
const logs = await prisma.adminLogs.findMany();
12+
res.status(200).json(logs);
13+
},
14+
{ statusCode: 500, message: "Couldn't get admin logs" }
15+
);
16+
17+
// get all sts manager logs
18+
// get all contractor manager logs
19+
20+
export { getAdminLogs };

server/src/prisma/schema.prisma

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ generator client {
88
}
99

1010
model User {
11-
id String @id @default(uuid())
12-
username String
13-
email String @unique
14-
hashedPassword String
15-
profileName String? // full name for contractor manager
16-
profileImage String?
17-
accessLevel String?
11+
id String @id @default(uuid())
12+
username String
13+
email String @unique
14+
hashedPassword String
15+
profileName String? // full name for contractor manager, and employeee
16+
profileImage String?
17+
accessLevel String?
18+
dateOfBirth DateTime?
19+
dateOfHire DateTime?
20+
jobTitle String?
21+
paymentRatePerHour Decimal?
22+
assignedRoute Route? @relation(fields: [routeId], references: [id])
23+
routeId String?
1824
1925
contactNumber String?
2026
@@ -69,6 +75,33 @@ model AdminLogs {
6975
description String
7076
}
7177

78+
model Route {
79+
id String @id @default(uuid())
80+
name String
81+
description String?
82+
Area Area? @relation(fields: [areaId], references: [id])
83+
areaId String?
84+
User User[]
85+
}
86+
87+
model Area {
88+
id String @id @default(uuid())
89+
name String
90+
routes Route[]
91+
CollectionPlan CollectionPlan[]
92+
}
93+
94+
model CollectionPlan {
95+
id String @id @default(uuid())
96+
area Area @relation(fields: [areaId], references: [id])
97+
areaId String
98+
collectionStartTime DateTime?
99+
durationForCollection Decimal?
100+
numberOfLaborers Decimal?
101+
numberOfVans Decimal?
102+
expectedWaste Decimal?
103+
}
104+
72105
model Contractor {
73106
id String @id @default(uuid()) // contractor id
74107
name String

server/src/prisma/seed.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ const roleData: Prisma.RoleCreateInput[] = [
2525
name: RoleName.UNASSIGNED,
2626
description: "Unassigned Role",
2727
},
28+
{
29+
name: RoleName.CONTRACTOR_MANAGER,
30+
description: "Contractor Manager Role",
31+
},
32+
{
33+
name: RoleName.CONTRACTOR_EMPLOYEE,
34+
description: "Contractor Employee Role",
35+
},
2836
];
2937

3038
const permissionData: Prisma.PermissionCreateInput[] = [
@@ -153,6 +161,40 @@ const roleAssignments = [
153161
},
154162
];
155163

164+
const routeData: Prisma.RouteCreateInput[] = [
165+
{
166+
id: "route1",
167+
name: "Mohakhali to Amin Bazar",
168+
description: "Route from Mohakhali to Amin Bazar",
169+
},
170+
// add 5 more routes
171+
{
172+
id: "route2",
173+
name: "Gulshan to Amin Bazar",
174+
description: "Route from Gulshan to Amin Bazar",
175+
},
176+
{
177+
id: "route3",
178+
name: "Bonani to Amin Bazar",
179+
description: "Route from Bonani to Amin Bazar",
180+
},
181+
{
182+
id: "route4",
183+
name: "Badda to Amin Bazar",
184+
description: "Route from Badda to Amin Bazar",
185+
},
186+
{
187+
id: "route5",
188+
name: "Jatrabari to Amin Bazar",
189+
description: "Route from Jatrabari to Amin Bazar",
190+
},
191+
{
192+
id: "route6",
193+
name: "Mohakhali to Gulshan",
194+
description: "Route from Mohakhali to Gulshan",
195+
},
196+
];
197+
156198
const userData: Prisma.UserCreateInput[] = [
157199
{
158200
username: "Admin",
@@ -529,6 +571,14 @@ async function main() {
529571
}
530572
}
531573

574+
console.log("Seeding routes...");
575+
for (const route of routeData) {
576+
const newRoute = await prisma.route.create({
577+
data: route,
578+
});
579+
console.log(newRoute);
580+
}
581+
532582
console.log("Seeding users...");
533583
for (const user of userData) {
534584
const newUser = await prisma.user.create({

server/src/routes/auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import express from "express";
22
import {
3+
createEmployee,
34
createManager,
45
createUser,
56
login,
@@ -15,6 +16,7 @@ import { PERMISSIONS } from "../permissions/permissions";
1516

1617
const router = express.Router();
1718

19+
router.route("/createempolyee").post(createEmployee);
1820
router.route("/createmanager").post(authChecker, createManager);
1921
router
2022
.route("/create")

server/src/routes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import tripRoute from "./trip";
1515
import scheduleRoute from "./schedule";
1616
import authChecker from "../middlewares/auth";
1717
import contractorRoute from "./contractor";
18+
import logRouter from "./logs";
1819

1920
router.use("/auth", authRoute);
2021
router.use("/users", userRoute);
@@ -31,5 +32,6 @@ router.use("/schedules", scheduleRoute);
3132

3233
// auth checker needed
3334
router.use("/contractors", contractorRoute);
35+
router.use("/logs", logRouter);
3436

3537
export default router;

server/src/routes/logs.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import express from "express";
2+
import { getAdminLogs } from "../controllers/logs";
3+
const router = express.Router();
4+
5+
router.route("/admin").get(getAdminLogs);
6+
7+
export default router;

0 commit comments

Comments
 (0)