Skip to content

Commit

Permalink
added new sql migration and more data payload for createService:
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMohit2003 committed Feb 22, 2024
1 parent e687cbf commit 7be6c83
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 29 deletions.
34 changes: 30 additions & 4 deletions controllers/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,44 @@ const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

const createService = async (req, res) => {
const { title, description, price } = req.body;
const userId = req.body.userId; // Assuming req.user is populated by your authentication middleware
const {
title,
description,
amount,
location,
biddingDate,
projectStartDate,
} = req.body;
const userId = req.userId; // Assuming req.userId is populated by your authentication middleware

try {
// Additional check to ensure the user is an issuer could be implemented here
// Fetch the user to check their role
const user = await prisma.user.findUnique({
where: { id: userId },
});

if (!user || user.role !== 'ISSUER') {
// Respond with an error if the user is not found or not an issuer
return res.status(403).json({
message: 'Forbidden - Only issuers can create services',
});
}

// If the user is an issuer, proceed to create the service
const service = await prisma.service.create({
data: {
title,
description,
price,
issuerId: userId, // Assuming the issuerId is the userId of the authenticated issuer
amount,
location,
biddingDate: new Date(biddingDate),
projectStartDate: new Date(projectStartDate),
issuerId: userId, // The userId from the request is the issuerId
status: 'OPEN', // Default status, can be omitted if set by default in Prisma schema
},
});

res.status(201).json({
service,
});
Expand All @@ -29,6 +54,7 @@ const createService = async (req, res) => {
const getAllServices = async (req, res) => {
try {
const services = await prisma.service.findMany();

res.status(200).json({
services,
});
Expand Down
14 changes: 14 additions & 0 deletions prisma/migrations/20240222073554_eight_migration/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Warnings:
- Added the required column `amount` to the `Service` table without a default value. This is not possible if the table is not empty.
- Added the required column `biddingDate` to the `Service` table without a default value. This is not possible if the table is not empty.
- Added the required column `location` to the `Service` table without a default value. This is not possible if the table is not empty.
- Added the required column `projectStartDate` to the `Service` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Service" ADD COLUMN "amount" INTEGER NOT NULL,
ADD COLUMN "biddingDate" TIMESTAMP(3) NOT NULL,
ADD COLUMN "location" TEXT NOT NULL,
ADD COLUMN "projectStartDate" TIMESTAMP(3) NOT NULL;
55 changes: 30 additions & 25 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,57 @@ model User {
}

model Issuer {
userId String @id
userId String @id
name String
contact Int?
aadhar String?
GST Int?
OrganizationName String?
IssuerType IssuerType
createdAt DateTime @default(now())
createdAt DateTime @default(now())
services Service[]
user User? @relation(fields: [userId], references: [id])
user User? @relation(fields: [userId], references: [id])
}

model Vendor {
userId String @id
userId String @id
name String
officeAddress String
contact Int
aadhar String
GST Int
OrganizationName String
WorkDescription String
Occupation String @default("Service Provider")
createdAt DateTime @default(now())
Occupation String @default("Service Provider")
createdAt DateTime @default(now())
bids Bid[]
user User @relation(fields: [userId], references: [id])
user User @relation(fields: [userId], references: [id])
}

model Service {
id String @id @default(uuid())
issuerId String
title String
description String
status ServiceStatus @default(OPEN)
createdAt DateTime @default(now())
bids Bid[]
issuer Issuer @relation(fields: [issuerId], references: [userId])
id String @id @default(uuid())
issuerId String
title String
amount Int
location String
//attachment
biddingDate DateTime
projectStartDate DateTime
description String
status ServiceStatus @default(OPEN)
createdAt DateTime @default(now())
bids Bid[]
issuer Issuer @relation(fields: [issuerId], references: [userId])
}

model Bid {
id String @id @default(uuid())
serviceId String
vendorId String
amount Float
message String?
status BidStatus @default(PENDING)
createdAt DateTime @default(now())
service Service @relation(fields: [serviceId], references: [id])
vendor Vendor @relation(fields: [vendorId], references: [userId])
}
id String @id @default(uuid())
serviceId String
vendorId String
amount Float
message String?
status BidStatus @default(PENDING)
createdAt DateTime @default(now())
service Service @relation(fields: [serviceId], references: [id])
vendor Vendor @relation(fields: [vendorId], references: [userId])
}

0 comments on commit 7be6c83

Please sign in to comment.