Skip to content

Commit

Permalink
feat: add geoData to Vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
saifali96 committed May 8, 2022
1 parent 263883e commit 3edc5ac
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/controllers/AdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const CreateVendor = async (req: Request, res: Response, next: NextFuncti
password: userPassword,
rating: 0,
coverImages: [],
foods: []
foods: [],
geoData: { lng: 0.0, lat: 0.0 }
});

return res.status(201).json({ success: true, message: createVendor });
Expand Down
31 changes: 19 additions & 12 deletions src/controllers/VendorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const VendorLogin = async (req: Request, res: Response, next: NextFunctio
}
}

return res.status(401).json({ success: false, message: "User does not exist." });
return res.status(400).json({ success: false, message: "User does not exist." });
}

export const GetVendorProfile = async (req: Request, res: Response, next: NextFunction) => {
Expand All @@ -49,25 +49,32 @@ export const GetVendorProfile = async (req: Request, res: Response, next: NextFu

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

const { foodType, name, address, phone } = <EditVendorInputs>req.body;
const user = req.user;

if (user) {
const { foodType, name, address, phone, geoData } = <EditVendorInputs>req.body;

const vendor = await FindVendor(user._id);

if(vendor !== null) {
const vendor = await FindVendor(req.user?._id);

if(vendor !== null) {
if (name) {
vendor.name = name;
}
if (address) {
vendor.address = address;
}
if (phone) {
vendor.phone = phone;
}
if (foodType) {
vendor.foodType = foodType;
}
if (geoData) {
vendor.geoData = geoData;
}

const savedResult = await vendor.save();
return res.status(201).json({ success: true, message: savedResult });
const savedResult = await vendor.save();

if(savedResult) {
return res.status(201).json({ success: true, message: savedResult });
}

return res.status(201).json({ success: true, message: vendor });
}

return res.status(400).json({ success: false, message: "Vendor profile not found." });
Expand Down
4 changes: 4 additions & 0 deletions src/dto/Vendor.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface EditVendorInputs {
address: string;
phone: string;
foodType: [string];
geoData: {
lng: number,
lat: number
}
}

export interface VendorLoginInputs {
Expand Down
12 changes: 10 additions & 2 deletions src/models/Vendor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ interface VendorDoc extends Document {
serviceAvailability: boolean;
coverImages: [string];
rating: number;
foods: any
foods: any;
geoData: {
lng: number
lat: number
};
}

const VendorSchema = new Schema({
Expand All @@ -32,7 +36,11 @@ const VendorSchema = new Schema({
foods: [{
type: mongoose.SchemaTypes.ObjectId,
ref: "food"
}]
}],
geoData: {
lng: { type: Number },
lat: { type: Number }
}
}, {
toJSON: {
transform(doc, ret){
Expand Down

0 comments on commit 3edc5ac

Please sign in to comment.