Skip to content

Commit 862624d

Browse files
authored
Merge pull request #86 from definecoder/domestic
logs and employee api and schema update
2 parents c39d03d + e3e8458 commit 862624d

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
@@ -90,6 +90,59 @@ const createManager = errorWrapper(
9090
{ statusCode: 500, message: `Couldn't create user` }
9191
);
9292

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