Skip to content

Commit a58dfe7

Browse files
author
shawon-majid
committed
collection plan added
1 parent def9a2a commit a58dfe7

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { PrismaClient } from "@prisma/client";
2+
import { Request, Response } from "express";
3+
4+
const prisma = new PrismaClient();
5+
6+
const addCollectionPlan = async (req: Request, res: Response) => {
7+
const payload = req.body;
8+
const newCollectionPlan = await prisma.collectionPlan.create({
9+
data: payload,
10+
});
11+
12+
res.status(201).json(newCollectionPlan);
13+
};
14+
15+
const getAllCollectionPlans = async (req: Request, res: Response) => {
16+
const collectionPlans = await prisma.collectionPlan.findMany();
17+
res.status(200).json(collectionPlans);
18+
};
19+
20+
const getCollectionPlansBySTS = async (req: Request, res: Response) => {
21+
const stsId = req.params.stsId;
22+
const collectionPlans = await prisma.collectionPlan.findMany({
23+
where: {
24+
stsId: stsId,
25+
},
26+
});
27+
28+
res.json(collectionPlans);
29+
};
30+
31+
export { addCollectionPlan, getAllCollectionPlans, getCollectionPlansBySTS };

server/src/prisma/schema.prisma

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ model CollectionPlan {
105105
numberOfLaborers Decimal?
106106
numberOfVans Decimal?
107107
expectedWaste Decimal?
108+
stsId String?
109+
sts STS? @relation(fields: [stsId], references: [id])
108110
}
109111

110112
model Contractor {
@@ -168,13 +170,14 @@ model STS {
168170
manager User[]
169171
Trip Trip[]
170172
171-
createdAt DateTime @default(now())
172-
updatedAt DateTime @updatedAt
173-
Bill Bill[]
174-
Schedule Schedule[]
175-
Contractor Contractor[]
176-
Route Route[]
177-
Area Area[]
173+
createdAt DateTime @default(now())
174+
updatedAt DateTime @updatedAt
175+
Bill Bill[]
176+
Schedule Schedule[]
177+
Contractor Contractor[]
178+
Route Route[]
179+
Area Area[]
180+
CollectionPlan CollectionPlan[]
178181
}
179182

180183
model Landfill {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import express from "express";
2+
const router = express.Router();
3+
4+
import {
5+
addCollectionPlan,
6+
getAllCollectionPlans,
7+
getCollectionPlansBySTS,
8+
} from "../controllers/collectionPlans";
9+
10+
router.route("/create").post(addCollectionPlan);
11+
router.route("/all").get(getAllCollectionPlans);
12+
router.route("/").get(getCollectionPlansBySTS);
13+
14+
export default router;

server/src/routes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import contractorRoute from "./contractor";
1818
import logRouter from "./logs";
1919
import routeAreaRouter from "./routeArea";
2020
import employeeRoute from "./employee";
21+
import collectionPlanRoute from "./collectionPlans";
2122

2223
router.use("/auth", authRoute);
2324
router.use("/users", userRoute);
@@ -37,5 +38,6 @@ router.use("/contractors", contractorRoute);
3738
router.use("/logs", logRouter);
3839
router.use("/route-areas", routeAreaRouter);
3940
router.use("/employees", employeeRoute);
41+
router.use("/collection-plans", collectionPlanRoute);
4042

4143
export default router;

0 commit comments

Comments
 (0)