Skip to content

Commit af8debc

Browse files
committed
2 parents 6209377 + f0892fc commit af8debc

File tree

6 files changed

+179
-9
lines changed

6 files changed

+179
-9
lines changed

server/src/controllers/collectionPlans.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,18 @@ const getAllCollectionPlans = errorWrapper(
6767
}
6868
);
6969

70-
const getCollectionPlansBySTS = async (req: Request, res: Response) => {
71-
const stsId = req.params.stsId;
72-
const collectionPlans = await prisma.collectionPlan.findMany({
73-
where: {
74-
stsId: stsId,
75-
},
76-
});
70+
const getCollectionPlansBySTS = errorWrapper(
71+
async (req: Request, res: Response) => {
72+
const stsId = req.params.stsId;
73+
const collectionPlans = await prisma.collectionPlan.findMany({
74+
where: {
75+
stsId: stsId,
76+
},
77+
});
7778

78-
res.json(collectionPlans);
79-
};
79+
res.json(collectionPlans);
80+
},
81+
{ statusCode: 404, message: "Collection Plans not found" }
82+
);
8083

8184
export { addCollectionPlan, getAllCollectionPlans, getCollectionPlansBySTS };

server/src/controllers/issue.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { PrismaClient } from "@prisma/client";
2+
import { Request, Response } from "express";
3+
import errorWrapper from "../middlewares/errorWrapper";
4+
import { adminLog } from "../services/logdata";
5+
6+
const prisma = new PrismaClient();
7+
8+
const addIssue = errorWrapper(
9+
async (req: Request, res: Response) => {
10+
const payload = req.body;
11+
const newIssue = await prisma.issue.create({
12+
data: payload,
13+
});
14+
15+
await adminLog("Issue Entry", `Issue ${newIssue.issueType} created`);
16+
17+
res.status(201).json(newIssue);
18+
},
19+
{ statusCode: 400, message: "Issue not created" }
20+
);
21+
22+
const getAllIssues = errorWrapper(
23+
async (req: Request, res: Response) => {
24+
const issues = await prisma.issue.findMany();
25+
res.status(200).json(issues);
26+
},
27+
{ statusCode: 404, message: "Issues not found" }
28+
);
29+
30+
export { addIssue, getAllIssues };

server/src/prisma/schema.prisma

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ model ContractorLogs {
7373
updatedAt DateTime @updatedAt
7474
}
7575

76+
model Issue {
77+
id String @id @default(uuid())
78+
issueType String
79+
description String
80+
latitude Decimal
81+
longitude Decimal
82+
isAnonymous Boolean
83+
issuePic String @default("https://thumbs.dreamstime.com/b/pile-garbage-home-junk-left-front-house-street-plastic-bags-dumper-truck-to-collect-pile-115303584.jpg")
84+
createdAt DateTime @default(now())
85+
updatedAt DateTime @updatedAt
86+
}
87+
7688
model AdminLogs {
7789
id String @id @default(uuid())
7890
type String

server/src/prisma/seed.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,37 +161,90 @@ const roleAssignments = [
161161
},
162162
];
163163

164+
const areaData: Prisma.AreaCreateInput[] = [
165+
{
166+
id: "area1",
167+
name: "Mohakhali",
168+
},
169+
{
170+
id: "area2",
171+
name: "Gulshan",
172+
},
173+
{
174+
id: "area3",
175+
name: "Bonani",
176+
},
177+
{
178+
id: "area4",
179+
name: "Badda",
180+
},
181+
{
182+
id: "area5",
183+
name: "Jatrabari",
184+
},
185+
];
186+
164187
const routeData: Prisma.RouteCreateInput[] = [
165188
{
166189
id: "route1",
167190
name: "Mohakhali to Amin Bazar",
168191
description: "Route from Mohakhali to Amin Bazar",
192+
area: {
193+
connect: {
194+
id: "area1",
195+
},
196+
},
169197
},
170198
// add 5 more routes
171199
{
172200
id: "route2",
173201
name: "Gulshan to Amin Bazar",
174202
description: "Route from Gulshan to Amin Bazar",
203+
area: {
204+
connect: {
205+
id: "area1",
206+
},
207+
},
175208
},
176209
{
177210
id: "route3",
178211
name: "Bonani to Amin Bazar",
179212
description: "Route from Bonani to Amin Bazar",
213+
area: {
214+
connect: {
215+
id: "area1",
216+
},
217+
},
180218
},
181219
{
182220
id: "route4",
183221
name: "Badda to Amin Bazar",
184222
description: "Route from Badda to Amin Bazar",
223+
area: {
224+
connect: {
225+
id: "area2",
226+
},
227+
},
185228
},
186229
{
187230
id: "route5",
188231
name: "Jatrabari to Amin Bazar",
189232
description: "Route from Jatrabari to Amin Bazar",
233+
area: {
234+
connect: {
235+
id: "area2",
236+
},
237+
},
190238
},
191239
{
192240
id: "route6",
193241
name: "Mohakhali to Gulshan",
194242
description: "Route from Mohakhali to Gulshan",
243+
area: {
244+
connect: {
245+
id: "area2",
246+
},
247+
},
195248
},
196249
];
197250

@@ -532,6 +585,7 @@ const tripData: Prisma.TripCreateInput[] = [
532585

533586
const contractorData: Prisma.ContractorCreateInput[] = [
534587
{
588+
id: "con1",
535589
name: "Contractor 2 Name",
536590
registrationId: "ABSDC123456",
537591
registrationDate: "2024-05-10T00:00:00Z",
@@ -550,6 +604,50 @@ const contractorData: Prisma.ContractorCreateInput[] = [
550604
},
551605
];
552606

607+
const employeeData: Prisma.UserCreateInput[] = [
608+
{
609+
username: "employee4",
610+
email: "employee4@example.com",
611+
hashedPassword: hashedP,
612+
role: {
613+
connect: {
614+
name: RoleName.CONTRACTOR_EMPLOYEE,
615+
},
616+
},
617+
dateOfBirth: "1990-01-01T00:00:00Z",
618+
contactNumber: "012321312",
619+
dateOfHire: "2024-05-10T00:00:00Z",
620+
jobTitle: "E Job Title",
621+
paymentRatePerHour: 20.0,
622+
Contractor: {
623+
connect: {
624+
id: "con1",
625+
},
626+
},
627+
},
628+
// add 5 more employees
629+
...Array.from({ length: 5 }, (_, i) => ({
630+
username: `employee${i + 5}`,
631+
email: `employee${i + 5}@example.com`,
632+
hashedPassword: hashedP,
633+
role: {
634+
connect: {
635+
name: RoleName.CONTRACTOR_EMPLOYEE,
636+
},
637+
},
638+
dateOfBirth: "1990-01-01T00:00:00Z",
639+
contactNumber: "012321312",
640+
dateOfHire: "2024-05-10T00:00:00Z",
641+
jobTitle: "E Job Title",
642+
paymentRatePerHour: 20.0,
643+
Contractor: {
644+
connect: {
645+
id: "con1",
646+
},
647+
},
648+
})),
649+
];
650+
553651
async function main() {
554652
console.log("Seeding roles...");
555653
for (const role of roleData) {
@@ -591,6 +689,14 @@ async function main() {
591689
}
592690
}
593691

692+
console.log("Seeding areas...");
693+
for (const area of areaData) {
694+
const newArea = await prisma.area.create({
695+
data: area,
696+
});
697+
console.log(newArea);
698+
}
699+
594700
console.log("Seeding routes...");
595701
for (const route of routeData) {
596702
const newRoute = await prisma.route.create({
@@ -655,6 +761,14 @@ async function main() {
655761
console.log(newContractor);
656762
}
657763

764+
console.log("Seeding employees...");
765+
for (const employee of employeeData) {
766+
const newEmployee = await prisma.user.create({
767+
data: employee,
768+
});
769+
console.log(newEmployee);
770+
}
771+
658772
console.log("Seeding completed!");
659773
}
660774

server/src/routes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import logRouter from "./logs";
1919
import routeAreaRouter from "./routeArea";
2020
import employeeRoute from "./employee";
2121
import collectionPlanRoute from "./collectionPlans";
22+
import issueRoute from "./issue";
2223

2324
router.use("/auth", authRoute);
2425
router.use("/users", userRoute);
@@ -39,5 +40,6 @@ router.use("/logs", logRouter);
3940
router.use("/route-areas", routeAreaRouter);
4041
router.use("/employees", employeeRoute);
4142
router.use("/collection-plans", collectionPlanRoute);
43+
router.use("/issues", issueRoute);
4244

4345
export default router;

server/src/routes/issue.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import express from "express";
2+
const router = express.Router();
3+
4+
import { addIssue, getAllIssues } from "../controllers/issue";
5+
6+
router.route("/create").post(addIssue);
7+
router.route("/all").get(getAllIssues);
8+
9+
export default router;

0 commit comments

Comments
 (0)