Skip to content

Commit

Permalink
add Offer.ts Model
Browse files Browse the repository at this point in the history
  • Loading branch information
saifali96 committed May 8, 2022
1 parent ce4acc7 commit c129397
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/controllers/VendorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,17 @@ export const ProcessOrder = async (req: Request, res: Response, next: NextFuncti
}
}

return res.status(400).json({ success: false, message: "Could not update order." });
return res.status(400).json({ success: false, message: "Could not process order." });
}

export const GetOffers = async (req: Request, res: Response, next: NextFunction) => {

}

export const AddOffer = async (req: Request, res: Response, next: NextFunction) => {

}

export const EditOffer = async (req: Request, res: Response, next: NextFunction) => {

}
63 changes: 63 additions & 0 deletions src/models/Offer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import mongoose, { Schema, Document } from "mongoose";

export interface OfferDoc extends Document {

offerType: string; // VENDOR - GENERIC
vendors: [any]; // [ "vendorID", "vendorID" ]
title: string; // EUR 10 off on weekdays
description: string; // Description with T&C
minValue: number; // Minimum order value should be EUR 15
offerAmount: number; // 10
validFrom: Date;
validUntil: Date;
promoCode: string; // WEEK10OFF
promoType: string; // USER - ALL - BANK - CARD
bank: [any];
bins: [any];
zipCode: string;
isActive: boolean;

}

const OfferSchema = new Schema({

offerType: { type: String, required: true },
vendors: [
{
type: Schema.Types.ObjectId,
ref: "vendor"
}
],
title: { type: String, required: true },
description: String,
minValue: { type: Number, required: true },
offerAmount: { type: Number, required: true },
validFrom: Date,
validUntil: Date,
promoCode: { type: String, required: true },
promoType: { type: Number, required: true },
bank: [
{
type: String
}
],
bins: [
{
type: Number
}
],
zipCode: { type: Number, required: true },
isActive: Boolean

}, {
toJSON: {
transform(doc, ret){
delete ret.__v;
}
},
timestamps: true
});

const Offer = mongoose.model<OfferDoc>("offer", OfferSchema);

export { Offer };
3 changes: 2 additions & 1 deletion src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./Vendor";
export * from "./Food";
export * from "./Food";
export * from "./Offer";
8 changes: 7 additions & 1 deletion src/routes/VendorRoute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express, { Request, Response, NextFunction } from "express";
import { AddFood, GetCurrentOrders, GetFoods, GetOrderDetails, GetVendorProfile, ProcessOrder, UpdateVendorCoverImage, UpdateVendorProfile, UpdateVendorService, VendorLogin } from "../controllers";
import { AddFood, AddOffer, EditOffer, GetCurrentOrders, GetFoods, GetOffers, GetOrderDetails, GetVendorProfile, ProcessOrder, UpdateVendorCoverImage, UpdateVendorProfile, UpdateVendorService, VendorLogin } from "../controllers";
import { Authenticate } from "../middlewares";
import multer from "multer";
import { v4 as uuidv4 } from "uuid";
Expand Down Expand Up @@ -38,4 +38,10 @@ router.get("/orders", GetCurrentOrders);
router.put("/orders/:id/process", ProcessOrder);
router.get("/orders/:id", GetOrderDetails);

// Offers
router.get("/offers", GetOffers);
router.post("/offers", AddOffer);
router.put("/offers/:id", EditOffer);
// delete offers

export { router as VendorRoute };

0 comments on commit c129397

Please sign in to comment.