Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proshow reg #27

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ dist
.yarn/install-state.gz
.pnp.*
tmp
dump
dump
.vscode
37 changes: 30 additions & 7 deletions controllers/orderController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const Order = require("../models/order")
const { Order } = require("../models/order")
const Events = require("../models/event")
const campusAmbassadors = require("../models/campusAmbassador")
const Users = require("../models/user")
const BigPromise = require("../middlewares/bigPromise")
const CustomError = require("../errors/customError")
const mailHelper = require("../utils/emailHelper")
const {
mailHelper,
sendMailForVerifiedProshow,
} = require("../utils/emailHelper")
const cloudinary = require("cloudinary")
const order = require("../models/order")
const mongoose = require("mongoose")
Expand All @@ -26,14 +29,20 @@ exports.createOrder = BigPromise(async (req, res, next) => {
console.log(orderEvents)

const orderEventsWithParticipants = orderEvents.map((event) => {
return {
const e = {
event: event.event,
participants: event.participants, // Add participants array here
name: event.name,
type: event.type,
price: event.price,
ticketCount: event.ticketCount,
}

if (event.type === "proshow") {
e.ticketCount = event.ticketCount
return e
}

return e
})

const parsedAmount = parseInt(totalAmount)
Expand Down Expand Up @@ -117,6 +126,8 @@ exports.createOrder = BigPromise(async (req, res, next) => {
},
})

console.log("Order", order)

if (referalCode) {
const ambassador = await campusAmbassadors.findOne({ referalCode })

Expand Down Expand Up @@ -201,6 +212,9 @@ exports.verifyOrder = BigPromise(async (req, res, next) => {
const order = await Order.findById(id)

if (order) {
console.log("Order to verify", order)

// return
order.orderVerified = true
await order.save({ validateBeforeSave: false })

Expand All @@ -215,13 +229,22 @@ exports.verifyOrder = BigPromise(async (req, res, next) => {
}
}

for await (const event of order.orderEvents) {
for (const event of order.orderEvents) {
const id = event.event
await updateEventTicket(id)
const singleEvent = await Events.findById(id)
await mailHelper(order, singleEvent,"verified")
if (singleEvent.eventType === "proshow") {
await sendMailForVerifiedProshow({
email: order.email,
eventName: singleEvent.name,
uniqueId: event.uniqueId,
eventDate: singleEvent.date,
})
} else {
await mailHelper(order, singleEvent, "verified")
}
}

res.status(200).json({
message: "Order verified successfully",
status: true,
Expand Down
79 changes: 42 additions & 37 deletions models/order.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
const mongoose = require("mongoose")
const validator = require("validator")
const { nanoid } = require("nanoid")

const orderedEventsSchema = new mongoose.Schema(
{
event: {
type: mongoose.Schema.ObjectId,
ref: "Events",
required: true,
},
participants: [
{
type: String,
},
],
name: {
type: String,
},
price: {
type: Number,
},
},
{ discriminatorKey: "type" }
)

const orderedProshowSchema = new mongoose.Schema({
uniqueId: {
type: String,
required: true,
default: () => nanoid(6),
index: { unique: true },
},
ticketCount: {
type: Number,
},
})

const orderSchema = new mongoose.Schema({
name: {
Expand Down Expand Up @@ -32,32 +67,7 @@ const orderSchema = new mongoose.Schema({
type: Boolean,
default: false,
},
orderEvents: [
{
event: {
type: mongoose.Schema.ObjectId,
ref: "Events",
required: true,
},
participants: [
{
type: String,
},
],
name: {
type: String,
},
type: {
type: String,
},
price: {
type: Number,
},
ticketCount: {
type: Number,
},
},
],
orderEvents: [orderedEventsSchema],
paymentInfo: {
id: {
type: String,
Expand All @@ -67,16 +77,6 @@ const orderSchema = new mongoose.Schema({
type: Number,
required: [true, "please provide the total amount"],
},
// paymentProof: {
// id: {
// type: String,
// required: [true, "please provide the payment proof"],
// },
// secure_url: {
// type: String,
// required: [true, "please provide the payment proof"],
// },
// },
createdAt: {
type: Date,
default: Date.now(),
Expand All @@ -92,4 +92,9 @@ const orderSchema = new mongoose.Schema({
},
})

module.exports = mongoose.model("Order", orderSchema)
orderSchema.path("orderEvents").discriminator("proshow", orderedProshowSchema)

const Order = mongoose.model("Order", orderSchema)
module.exports = { Order }
// module.exports = orderedProshow
// module.exports = orderedEvents
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"mongoose": "^7.1.0",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"nanoid": "^3.3.4",
"nodemailer": "^6.9.2",
"razorpay": "^2.8.6",
"uuid": "^9.0.0",
Expand Down
Loading