ashok 11 months ago
commit b447b50273

@ -742,15 +742,9 @@ exports.addTeamMembers = async (req, reply) => {
try {
const customerId = req.params.customerId
//const username = req.params.username;
console.log(req.params);
//const {username} = loginObject.user.username;
//console.log(loginObject.user.username)
// const userInfo = await User.findOne({ username: username.toString() });
// const updateData = req.body;
// console.log("This is the reply in the handler after the validations", reply);
deliveryData = {
customerId: customerId,
teamAdminName: req.body.teamAdminName,
@ -791,3 +785,38 @@ exports.addTeamMembers = async (req, reply) => {
throw boom.boomify(err);
}
};
exports.deleteTeamMember = async (req, reply) => {
try {
var customerId = req.params.customerId;
var phone = req.query.phone;
const delivery = await AddTeamMembers.findOneAndDelete({
phone: phone,
customerId: customerId,
});
reply.send({ status_code: 200, data: delivery });
} catch (err) {
throw boom.boomify(err);
}
};
exports.updateTeamMember = async (req, reply) => {
try {
var customerId = req.params.customerId;
var phone = req.query.phone;
const delivery = req.body;
const { ...updateData } = delivery;
const update = await AddTeamMembers.findOneAndUpdate(
{ phone: phone, customerId: customerId },
updateData,
{ new: true }
);
console.log(update);
//return update;
reply.send({ status_code: 200, data: update });
} catch (err) {
throw boom.boomify(err);
}
};

@ -653,6 +653,80 @@ module.exports = function (fastify, opts, next) {
handler: userController.addTeamMembers,
});
fastify.route({
method: "PUT",
url: "/api/deleteTeamMember/:customerId",
schema: {
tags: ["User"],
summary: "This is for delete Team Member",
description: "This is for delete Team Member",
params: {
required: ["customerId"],
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
querystring: {
phone: { type: "string" },
},
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: userController.deleteTeamMember, // Ensure this line points to the handler
});
fastify.route({
method: "PUT",
url: "/api/updateTeamMeber/:customerId",
schema: {
tags: ["User"],
summary: "This is for update Team Member details",
params: {
required: ["customerId"],
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
querystring: {
phone: {type: 'string'}
},
body: {
type: "object",
// required: ['phone'],
properties: {
name: { type: "string", default: null },
phone: { type: "string", default: null },
alternativeContactNumber: { type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: [
// fastify.auth([fastify.operatorAuthenticate]),
// validationHandler.validatePhoneFormat,
// ],
// preHandler: fastify.auth([fastify.authenticate]),
handler: userController.updateTeamMember,
});
fastify.route({
method: "DELETE",

Loading…
Cancel
Save