You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
797 lines
20 KiB
797 lines
20 KiB
const fastify = require("fastify");
|
|
const supplierController = require("../controllers/supplierController");
|
|
const validationHandler = require("../handlers/supplierHandler");
|
|
const { profilePictureSupplier } = require("../models/supplier");
|
|
|
|
|
|
|
|
|
|
module.exports = function (fastify, opts, next) {
|
|
|
|
fastify.get("/api/suppliers/:customerId", {
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
description: "This is for Get All Suppliers",
|
|
summary: "This is for to Get All Suppliers",
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
customerId: {
|
|
type: "string",
|
|
description: "customerId",
|
|
},
|
|
},
|
|
},
|
|
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
handler: validationHandler.getSuppliers,
|
|
});
|
|
|
|
|
|
fastify.get("/api/connectedSuppliers/:customerId", {
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
description: "This is for Get All connected Suppliers",
|
|
summary: "This is for to Get All connected Suppliers",
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
customerId: {
|
|
type: "string",
|
|
description: "customerId",
|
|
},
|
|
},
|
|
},
|
|
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.getConnectedSuppliers,
|
|
});
|
|
|
|
|
|
fastify.get("/api/pendingSuppliers/:customerId", {
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
description: "This is for Get All pending Suppliers",
|
|
summary: "This is for to Get All pending Suppliers",
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
customerId: {
|
|
type: "string",
|
|
description: "customerId",
|
|
},
|
|
},
|
|
},
|
|
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.getPendingSuppliers,
|
|
});
|
|
|
|
fastify.get("/api/rejectSuppliers/:customerId", {
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
description: "This is for Get All rejected Suppliers",
|
|
summary: "This is for to Get All rejected Suppliers",
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
customerId: {
|
|
type: "string",
|
|
description: "customerId",
|
|
},
|
|
},
|
|
},
|
|
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.getRejectSuppliers,
|
|
});
|
|
|
|
|
|
|
|
fastify.get("/api/rejectCustomers/:supplierId", {
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
description: "This is for Get All rejected Customers",
|
|
summary: "This is for to Get All rejected Customers",
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
supplierId: {
|
|
type: "string",
|
|
description: "supplierId",
|
|
},
|
|
},
|
|
},
|
|
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.getRejectCustomers,
|
|
});
|
|
|
|
|
|
fastify.get("/api/pendingCustomers/:supplierId", {
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
description: "This is for Get All pending Customers",
|
|
summary: "This is for to Get All pending Customers",
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
supplierId: {
|
|
type: "string",
|
|
description: "supplierId",
|
|
},
|
|
},
|
|
},
|
|
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.getPendingCustomers,
|
|
});
|
|
|
|
|
|
|
|
fastify.get("/api/connectedCustomers/:supplierId", {
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
description: "This is for Get All connected Customers for Suppliers",
|
|
summary: "This is for to Get All connected Customers for suppliers",
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
supplierId: {
|
|
type: "string",
|
|
description: "supplierId",
|
|
},
|
|
},
|
|
},
|
|
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.getconnectedCustomers,
|
|
});
|
|
|
|
|
|
fastify.post("/api/supplierlogin", {
|
|
schema: {
|
|
description: "This is for Login Supplier",
|
|
tags: ["Supplier-Data"],
|
|
summary: "This is for Login Supplier",
|
|
body: {
|
|
type: "object",
|
|
required: ["phone", "password"],
|
|
properties: {
|
|
phone: { type: "string" },
|
|
password: { type: "string" },
|
|
},
|
|
},
|
|
},
|
|
handler: validationHandler.loginSupplier,
|
|
});
|
|
|
|
|
|
fastify.post("/api/deliveryboylogin", {
|
|
schema: {
|
|
description: "This is for Login Delivery Boy",
|
|
tags: ["Delivery"],
|
|
summary: "This is for Login Delivery Boy",
|
|
body: {
|
|
type: "object",
|
|
required: ["phone"],
|
|
properties: {
|
|
phoneVerificationCode: { type: "string" },
|
|
phone: { type: "string" },
|
|
},
|
|
},
|
|
},
|
|
handler: validationHandler.deliveryBoyVerifyPhone,
|
|
});
|
|
|
|
fastify.route({
|
|
method: "POST",
|
|
url: "/api/supplierlogout",
|
|
schema: {
|
|
description: "This is for Supplier logout",
|
|
tags: ["Supplier-Data"],
|
|
summary: "This is for Supplier logout",
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
supplierId: {
|
|
type: "string",
|
|
description: "supplierId",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
// preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.logoutsupplier,
|
|
// onResponse: (request,reply) => {validationHandler.resetPassword(request,reply)}
|
|
});
|
|
|
|
|
|
|
|
|
|
fastify.route({
|
|
method: "POST",
|
|
url: "/api/suppliers",
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
description: "This is for cretae New supplier",
|
|
summary: "This is for Create New supplier.",
|
|
body: {
|
|
type: "object",
|
|
properties: {
|
|
suppliername: { type: "string" },
|
|
phone: { type: "string" },
|
|
alternativeContactNumber : { type : "string" },
|
|
password: { type: "string" },
|
|
emails: {
|
|
type: "array",
|
|
maxItems: 2,
|
|
items: {
|
|
type: "object",
|
|
properties: {
|
|
email: { type: "string", default: null },
|
|
},
|
|
},
|
|
},
|
|
office_address: { type: "string", default: null },
|
|
city: { type: "string", default: null },
|
|
state: { type: "string", default: null },
|
|
zip: { type: "string", default: null },
|
|
country: { type: "string", default: null },
|
|
latitude: { type: 'number', default: 0.0},
|
|
longitude: { type: 'number', default: 0.0},
|
|
fcmId: { type: "string", default: null },
|
|
description: { type: "string", default: null },
|
|
|
|
},
|
|
},
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: [
|
|
validationHandler.fieldCheck,
|
|
validationHandler.verifySupplier,
|
|
// validationHandler.validatePhoneFormat,
|
|
validationHandler.validateEmailFormat,
|
|
],
|
|
handler: supplierController.addSupplier,
|
|
});
|
|
|
|
|
|
fastify.route({
|
|
method: "POST",
|
|
url: "/api/supplierphone",
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
description: "This is for verify Supplier Phone",
|
|
summary: "This is to Verify Supplier Phone.",
|
|
body: {
|
|
type: "object",
|
|
required: ["phone"],
|
|
properties: {
|
|
phoneVerificationCode: { type: "string" },
|
|
phone: { type: "string" },
|
|
},
|
|
},
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
// preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.verifyPhone,
|
|
});
|
|
|
|
|
|
fastify.route({
|
|
method: "POST",
|
|
url: "/api/deliveryboyphone",
|
|
schema: {
|
|
tags: ["Delivery"],
|
|
description: "This is for verify Delivery Boy Phone",
|
|
summary: "This is to Verify Delivery Boy Phone.",
|
|
body: {
|
|
type: "object",
|
|
required: ["phone"],
|
|
properties: {
|
|
phoneVerificationCode: { type: "string" },
|
|
phone: { type: "string" },
|
|
},
|
|
},
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
// preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.deliveryBoyVerifyPhone,
|
|
});
|
|
|
|
fastify.route({
|
|
method: "PUT",
|
|
url: "/api/deletedeliveryboy/:supplierId",
|
|
schema: {
|
|
tags: ["Delivery"],
|
|
summary: "This is for delete delivery boy",
|
|
description: "This is for delete delivery boy",
|
|
params: {
|
|
required: ["supplierId"],
|
|
type: "object",
|
|
properties: {
|
|
supplierId: {
|
|
type: "string",
|
|
description: "supplierId",
|
|
},
|
|
},
|
|
},
|
|
querystring: {
|
|
phone: {type: 'string'}
|
|
},
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.deleteDeliveryBoy,
|
|
});
|
|
|
|
|
|
|
|
fastify.route({
|
|
method: "PUT",
|
|
url: "/api/updatedeliveryboy/:supplierId",
|
|
schema: {
|
|
tags: ["Delivery"],
|
|
summary: "This is for update deliveryboy details",
|
|
params: {
|
|
required: ["supplierId"],
|
|
type: "object",
|
|
properties: {
|
|
supplierId: {
|
|
type: "string",
|
|
description: "supplierId",
|
|
},
|
|
},
|
|
},
|
|
querystring: {
|
|
phone: {type: 'string'}
|
|
},
|
|
|
|
body: {
|
|
type: "object",
|
|
// required: ['phone'],
|
|
properties: {
|
|
|
|
name: { type: "string", default: null },
|
|
phone: { type: "string", default: null },
|
|
alternativeContactNumber: { type: "string" },
|
|
address: { type: "string", default: null },
|
|
city: { type: "string" , default: null},
|
|
state: { type: "string", default: null },
|
|
zip: { type: "string", default: null },
|
|
},
|
|
},
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
// preHandler: [
|
|
// fastify.auth([fastify.operatorAuthenticate]),
|
|
// validationHandler.validatePhoneFormat,
|
|
// ],
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.updateDeliveryBoy,
|
|
});
|
|
|
|
|
|
|
|
fastify.route({
|
|
method: "POST",
|
|
url: "/api/suppliers/:supplierId",
|
|
schema: {
|
|
description: "To Get Supplier by supplierId",
|
|
tags: ["Supplier-Data"],
|
|
summary: "This is for Get a Single Supplier by supplierId",
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
supplierId: {
|
|
type: "string",
|
|
description: "supplierId",
|
|
},
|
|
},
|
|
},
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.getSingleSupplier,
|
|
});
|
|
|
|
|
|
fastify.route({
|
|
method: "POST",
|
|
url: "/api/currentsupplier",
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
description: "This is for Get Current Supplier by supplierId by Post Body",
|
|
summary: "This is for Get a Current Supplier.",
|
|
body: {
|
|
type: "object",
|
|
required: ["supplierId"],
|
|
properties: {
|
|
supplierId: { type: "string" },
|
|
},
|
|
},
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
handler: validationHandler.getCurrentSupplier,
|
|
|
|
});
|
|
|
|
fastify.route({
|
|
method: "PUT",
|
|
url: "/api/update/currentSupplier/:supplierId",
|
|
schema: {
|
|
tags: ["Supplier-Data"],
|
|
summary: "This is for update current supplier",
|
|
description: "This is for update current supplier",
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
supplierId: {
|
|
type: "string",
|
|
description: "supplierId",
|
|
},
|
|
},
|
|
},
|
|
body: {
|
|
type: "object",
|
|
properties: {
|
|
phone: { type: "string" },
|
|
firstName: { type: "string" },
|
|
lastName: { type: "string" },
|
|
suppliername: { type: "string" },
|
|
emails: {
|
|
type: "array",
|
|
maxItems: 2,
|
|
items: {
|
|
type: "object",
|
|
properties: {
|
|
email: { type: "string", default: null },
|
|
},
|
|
},
|
|
},
|
|
office_address: { type: "string" },
|
|
alternativeContactNumber: { type: "string" },
|
|
city: { type: "string" },
|
|
state: { type: "string" },
|
|
country: { type: "string" },
|
|
zip: { type: "string" },
|
|
description: { type: "string" },
|
|
status: {type: "string" },
|
|
startingPrice : {type : "string"}
|
|
},
|
|
},
|
|
security: [
|
|
{
|
|
basicAuth: [],
|
|
},
|
|
],
|
|
},
|
|
preHandler: [fastify.auth([fastify.authenticate])],
|
|
handler: supplierController.editCuurentSupplierInfo,
|
|
});
|
|
|
|
|
|
// fastify.route({
|
|
// method: "POST",
|
|
// url: "/api/supplier/profile-picture/:supplierId",
|
|
// schema: {
|
|
// tags: ["Supplier"],
|
|
// description: "This is for uploading profile picture supplier.",
|
|
// summary: "This is for uploading profile picture supplier.",
|
|
// params: {
|
|
// type: "object",
|
|
// properties: {
|
|
// supplierId: {
|
|
// type: "string",
|
|
// description: "supplierId",
|
|
// },
|
|
// },
|
|
// },
|
|
// body: {
|
|
// type: "object",
|
|
// required: ["picture"],
|
|
// properties: {
|
|
// picture: {
|
|
// type: 'string'
|
|
// }
|
|
// },
|
|
// },
|
|
// security: [
|
|
// {
|
|
// basicAuth: [],
|
|
// },
|
|
// ],
|
|
// },
|
|
// handler: validationHandler.uploadProfilePicture,
|
|
// });
|
|
|
|
|
|
// fastify.route({
|
|
// method: 'POST',
|
|
// url: '/api/users/profile-picture-supplier',
|
|
// schema: {
|
|
// tags: ['Supplier'],
|
|
// description: 'Upload a profile picture for a supplier',
|
|
// summary: 'Upload a profile picture for a supplier',
|
|
// params: {
|
|
// type: 'object',
|
|
// properties: {
|
|
// supplierId: {
|
|
// type: 'string',
|
|
// description: 'Supplier ID',
|
|
// },
|
|
// },
|
|
// },
|
|
// consumes: ['multipart/form-data'],
|
|
// body: {
|
|
// type: 'object',
|
|
// properties: {
|
|
// picture: {
|
|
// type: 'string',
|
|
// description: 'Profile picture file',
|
|
// },
|
|
// },
|
|
// required: ['picture'],
|
|
// },
|
|
// response: {
|
|
// 200: {
|
|
// description: 'Profile picture uploaded successfully',
|
|
// type: 'object',
|
|
// properties: {
|
|
// message: { type: 'string' },
|
|
// },
|
|
// },
|
|
// 400: {
|
|
// description: 'Failed to upload profile picture',
|
|
// type: 'object',
|
|
// properties: {
|
|
// error: { type: 'string' },
|
|
// },
|
|
// },
|
|
// 500: {
|
|
// description: 'Internal server error',
|
|
// type: 'object',
|
|
// properties: {
|
|
// error: { type: 'string' },
|
|
// },
|
|
// },
|
|
// },
|
|
// },
|
|
// handler: validationHandler.uploadProfilePicture,
|
|
// });
|
|
fastify.route({
|
|
method: 'POST',
|
|
url: '/api/users/profile-picture-supplier/:supplierId',
|
|
schema: {
|
|
tags: ['Supplier'],
|
|
description: 'Upload a profile picture for a supplier',
|
|
summary: 'Upload a profile picture for a supplier',
|
|
params: {
|
|
type: 'object',
|
|
properties: {
|
|
supplierId: {
|
|
type: 'string',
|
|
description: 'Supplier ID',
|
|
},
|
|
},
|
|
},
|
|
consumes: ['multipart/form-data'],
|
|
body: {
|
|
type: 'object',
|
|
properties: {
|
|
picture: {
|
|
type: 'object',
|
|
properties: {
|
|
data: { type: 'string' }, // Remove the "format" property
|
|
encoding: { type: 'string' },
|
|
filename: { type: 'string' },
|
|
},
|
|
required: ['data', 'encoding', 'filename'], // Add required properties
|
|
},
|
|
},
|
|
required: ['picture'],
|
|
},
|
|
response: {
|
|
200: {
|
|
description: 'Profile picture uploaded successfully',
|
|
type: 'object',
|
|
properties: {
|
|
message: { type: 'string' },
|
|
},
|
|
},
|
|
400: {
|
|
description: 'Failed to upload profile picture',
|
|
type: 'object',
|
|
properties: {
|
|
error: { type: 'string' },
|
|
},
|
|
},
|
|
500: {
|
|
description: 'Internal server error',
|
|
type: 'object',
|
|
properties: {
|
|
error: { type: 'string' },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
handler: validationHandler.uploadProfilePicture,
|
|
});
|
|
|
|
|
|
const multer = require('multer');
|
|
const fs = require('fs');
|
|
|
|
const storage = multer.diskStorage({
|
|
destination: function (req, file, cb) {
|
|
if (!fs.existsSync(__dirname + '/temp')) {
|
|
fs.mkdirSync(__dirname + '/temp');
|
|
}
|
|
cb(null, './temp');
|
|
},
|
|
filename: function (req, file, cb) {
|
|
cb(null, file.originalname + '-' + Date.now() + '.' + file.mimetype.split('/')[1]);
|
|
},
|
|
});
|
|
|
|
const upload = multer({ storage: storage }).single('picture');
|
|
|
|
// fastify.route({
|
|
// method: 'POST',
|
|
// url: '/api/users/profile-picture-supplier/:supplierId',
|
|
// schema: {
|
|
// tags: ['Supplier'],
|
|
// description: 'Upload a profile picture supplier',
|
|
// summary: 'Upload a profile picture supplier',
|
|
// params: {
|
|
// type: 'object',
|
|
// properties: {
|
|
// supplierId: {
|
|
// type: 'string',
|
|
// description: 'SupplierId',
|
|
// },
|
|
// },
|
|
// },
|
|
// body: {
|
|
// formData: {
|
|
// picture: {
|
|
// type: 'string',
|
|
// format: 'binary',
|
|
// description: 'Profile picture file',
|
|
// },
|
|
// },
|
|
// },
|
|
// response: {
|
|
// 200: {
|
|
// description: 'Profile picture uploaded successfully',
|
|
// type: 'object',
|
|
// properties: {
|
|
// message: { type: 'string' },
|
|
// },
|
|
// },
|
|
// 400: {
|
|
// description: 'Failed to upload profile picture',
|
|
// type: 'object',
|
|
// properties: {
|
|
// error: { type: 'string' },
|
|
// },
|
|
// },
|
|
// 500: {
|
|
// description: 'Internal server error',
|
|
// type: 'object',
|
|
// properties: {
|
|
// error: { type: 'string' },
|
|
// },
|
|
// },
|
|
// },
|
|
// },
|
|
// handler: async (req, reply) => {
|
|
// try {
|
|
// upload(req, reply, async (err) => {
|
|
// if (err) {
|
|
// reply.status(400).send({ error: 'Failed to upload profile picture' });
|
|
// return;
|
|
// }
|
|
|
|
// const supplierId = req.params.supplierId;
|
|
// const picturePath = req.file.path;
|
|
|
|
// let profilePicture = await profilePictureSupplier.findOne({ supplierId });
|
|
|
|
// if (!profilePicture) {
|
|
// profilePicture = new ProfilePicture({
|
|
// supplierId,
|
|
// picture: fs.readFileSync(picturePath),
|
|
// });
|
|
// } else {
|
|
// profilePicture.picture = fs.readFileSync(picturePath);
|
|
// }
|
|
|
|
// await profilePicture.save();
|
|
|
|
// // Delete the temporary uploaded file
|
|
// fs.unlinkSync(picturePath);
|
|
|
|
// reply.send({ message: 'Profile picture uploaded successfully' });
|
|
// });
|
|
// } catch (error) {
|
|
// reply.status(500).send({ error: error.message });
|
|
// }
|
|
// },
|
|
// });
|
|
|
|
next();
|
|
}
|
|
|