Skip to content

Commit fee2e6a

Browse files
authored
Merge pull request #93 from definecoder/contractor-bill
sts-conttactor entry
2 parents e64e89c + ed7f6ff commit fee2e6a

File tree

4 files changed

+92
-11
lines changed

4 files changed

+92
-11
lines changed
Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
11
import { PrismaClient } from "@prisma/client";
22
import { Request, Response } from "express";
3+
import { adminLog } from "../services/logdata";
4+
import errorWrapper from "../middlewares/errorWrapper";
35

46
const prisma = new PrismaClient();
57

6-
// const addSTSContractorEntry = async (req: Request, res: Response) => {
8+
const addContractorEntry = errorWrapper(
9+
async (req: Request, res: Response) => {
10+
const payload = req.body;
11+
const newContractorEntry = await prisma.sTSContractorEntry.create({
12+
data: payload,
13+
});
14+
15+
await adminLog(
16+
"Contractor Entry",
17+
`${newContractorEntry.vehicleNumber} has entered STS ${newContractorEntry.stsId}`
18+
);
19+
20+
res.status(201).json(newContractorEntry);
21+
},
22+
{ statusCode: 400, message: "Contractor Entry not created" }
23+
);
24+
25+
const getAllContractorEntries = errorWrapper(
26+
async (req: Request, res: Response) => {
27+
const contractorEntries = await prisma.sTSContractorEntry.findMany();
28+
res.status(200).json(contractorEntries);
29+
},
30+
{ statusCode: 404, message: "Contractor Entries not found" }
31+
);
32+
33+
const getContractorEntryById = errorWrapper(
34+
async (req: Request, res: Response) => {
35+
const { contractorEntryId } = req.params;
36+
const contractorEntry = await prisma.sTSContractorEntry.findUnique({
37+
where: {
38+
id: contractorEntryId,
39+
},
40+
});
41+
42+
if (!contractorEntry) {
43+
res.status(404).json({ message: "Contractor Entry not found" });
44+
}
45+
46+
res.status(200).json(contractorEntry);
47+
},
48+
{ statusCode: 404, message: "Contractor Entry not found" }
49+
);
50+
51+
export { addContractorEntry, getAllContractorEntries, getContractorEntryById };

server/src/prisma/schema.prisma

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ model Contractor {
155155
156156
manager User[]
157157
158-
createdAt DateTime @default(now())
159-
updatedAt DateTime @updatedAt
158+
createdAt DateTime @default(now())
159+
updatedAt DateTime @updatedAt
160+
STSContractorEntry STSContractorEntry[]
160161
}
161162

162163
model Vehicle {
@@ -201,14 +202,15 @@ model STS {
201202
manager User[]
202203
Trip Trip[]
203204
204-
createdAt DateTime @default(now())
205-
updatedAt DateTime @updatedAt
206-
Bill Bill[]
207-
Schedule Schedule[]
208-
Contractor Contractor[]
209-
Route Route[]
210-
Area Area[]
211-
CollectionPlan CollectionPlan[]
205+
createdAt DateTime @default(now())
206+
updatedAt DateTime @updatedAt
207+
Bill Bill[]
208+
Schedule Schedule[]
209+
Contractor Contractor[]
210+
Route Route[]
211+
Area Area[]
212+
CollectionPlan CollectionPlan[]
213+
STSContractorEntry STSContractorEntry[]
212214
}
213215

214216
model Landfill {
@@ -248,6 +250,24 @@ model STSVehicleEntry {
248250
updatedAt DateTime @updatedAt
249251
}
250252

253+
model STSContractorEntry {
254+
id String @id @default(uuid())
255+
sts STS @relation(fields: [stsId], references: [id], onDelete: Cascade)
256+
stsId String
257+
contractor Contractor @relation(fields: [contractorId], references: [id], onDelete: Cascade)
258+
contractorId String
259+
260+
wasteType String?
261+
wasteWeight Decimal? @db.Decimal(10, 2)
262+
entryTime DateTime?
263+
exitTime DateTime?
264+
265+
vehicleNumber String?
266+
267+
createdAt DateTime @default(now())
268+
updatedAt DateTime @updatedAt
269+
}
270+
251271
model LandfillVehicleEntry {
252272
id String @id @default(uuid())
253273
landfill Landfill @relation(fields: [landfillId], references: [id], onDelete: Cascade)

server/src/routes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import routeAreaRouter from "./routeArea";
2020
import employeeRoute from "./employee";
2121
import collectionPlanRoute from "./collectionPlans";
2222
import issueRoute from "./issue";
23+
import stsContractorRoute from "./stsContractor";
2324

2425
router.use("/auth", authRoute);
2526
router.use("/users", userRoute);
@@ -41,5 +42,6 @@ router.use("/route-areas", routeAreaRouter);
4142
router.use("/employees", employeeRoute);
4243
router.use("/collection-plans", collectionPlanRoute);
4344
router.use("/issues", issueRoute);
45+
router.use("/sts-contractor-entry", stsContractorRoute);
4446

4547
export default router;

server/src/routes/stsContractor.ts

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+
addContractorEntry,
6+
getAllContractorEntries,
7+
getContractorEntryById,
8+
} from "../controllers/stsContractorEntry";
9+
10+
router.route("/create").post(addContractorEntry);
11+
router.route("/all").get(getAllContractorEntries);
12+
router.route("/:id").get(getContractorEntryById);
13+
14+
export default router;

0 commit comments

Comments
 (0)