|
|
|
const fastify = require("fastify");
|
|
|
|
const supplierController = require("../controllers/supplierController");
|
|
|
|
const validationHandler = require("../handlers/supplierHandler");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function (fastify, opts, next) {
|
|
|
|
|
|
|
|
fastify.get("/api/suppliers", {
|
|
|
|
schema: {
|
|
|
|
tags: ["Supplier-Data"],
|
|
|
|
description: "This is for Get All Suppliers",
|
|
|
|
summary: "This is for to Get All Suppliers",
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
handler: validationHandler.getSuppliers,
|
|
|
|
});
|
|
|
|
|
|
|
|
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.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' },
|
|
|
|
longitude: { type: 'number'}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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/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" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: [fastify.auth([fastify.authenticate])],
|
|
|
|
handler: supplierController.editCuurentSupplierInfo,
|
|
|
|
});
|
|
|
|
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|