Bhaskara Kishore 3 years ago
commit 33a6689dad

@ -60,7 +60,6 @@ console.log(req.params);
tankers.alternative_phoneNumber = usertobeInserted.alternative_phoneNumber; tankers.alternative_phoneNumber = usertobeInserted.alternative_phoneNumber;
tankers.capacity = usertobeInserted.capacity; tankers.capacity = usertobeInserted.capacity;
tankers.typeofwater = usertobeInserted.typeofwater; tankers.typeofwater = usertobeInserted.typeofwater;
tankers.supplierId = usertobeInserted.supplierId;
tankers.price = usertobeInserted.price; tankers.price = usertobeInserted.price;
tankers.status = usertobeInserted.status; tankers.status = usertobeInserted.status;
} }

@ -14,10 +14,10 @@ exports.friendRequest = async (request, reply) => {
const { senderId, receiverId } = request.body; const { senderId, receiverId } = request.body;
// Check if the sender and receiver exist in the database // Check if the sender and receiver exist in the database
const sender = await User.findOne(senderId); const sender = await User.findById(senderId);
const receiver = await Supplier.findOne(receiverId); const receiver = await Supplier.findById(receiverId);
console.log("sender" , sender.customerId) console.log("sender" , sender)
console.log("receiver" , receiver.supplierId) console.log("receiver" , receiver)
if (!sender || !receiver) { if (!sender || !receiver) {
@ -25,21 +25,22 @@ exports.friendRequest = async (request, reply) => {
} }
// Check if a friend request already exists between the two users // Check if a friend request already exists between the two users
const existingRequest = await FriendRequest.findOne({ customerId: sender.customerId, supplierId: receiver.supplierId}); const existingRequest = await FriendRequest.findOne({ sender: senderId, receiver: receiverId });
console.log(existingRequest, " .. exist")
if (existingRequest) { if (existingRequest) {
throw new Error('Friend request already sent'); throw new Error('Friend request already sent');
} }
// Create a new friend request // Create a new friend request
const friendRequest = new FriendRequest({ customerId: sender.customerId, supplierId: receiver.supplierId}); const friendRequest = new FriendRequest({
sender: senderId,
receiver: receiverId
});
await friendRequest.save(); await friendRequest.save();
console.log("friendRequest", friendRequest) console.log("friendRequest", friendRequest)
reply.send({ message: 'Friend request sent' }); reply.send({ message: 'Friend request sent' });
} catch (err) { } catch (err) {
reply.status(400).send({ error: err.message }); reply.status(400).send({ error: err.message });
} }
@ -48,10 +49,10 @@ exports.friendRequest = async (request, reply) => {
// Handle friend request acceptance // Handle friend request acceptance
exports.friendRequestAccept = async (request, reply) => { exports.friendRequestAccept = async (request, reply) => {
try { try {
const {supplierId} = request.body; const {friendRequestId} = request.body;
// Update the friend request status to 'accepted' // Update the friend request status to 'accepted'
const friendRequest = await FriendRequest.findOneAndUpdate({supplierId}, { status: 'accepted' }); const friendRequest = await FriendRequest.findByIdAndUpdate(friendRequestId, { status: 'accepted' });
console.log("friendRequest....---", friendRequest) console.log("friendRequest....---", friendRequest)
@ -69,10 +70,10 @@ exports.friendRequestAccept = async (request, reply) => {
// Handle friend request rejection // Handle friend request rejection
exports.friendRequestReject = async (request, reply) => { exports.friendRequestReject = async (request, reply) => {
try { try {
const {supplierId} = request.body; const {friendRequestId} = request.body;
// Update the friend request status to 'reject' // Update the friend request status to 'rejected'
const friendRequest = await FriendRequest.findOneAndUpdate({supplierId}, { status: 'rejected' }); const friendRequest = await FriendRequest.findByIdAndUpdate(friendRequestId, { status: 'rejected' });
console.log("friendRequest....---", friendRequest) console.log("friendRequest....---", friendRequest)

@ -94,8 +94,8 @@ const supplierSchema = new mongoose.Schema(
// }) // })
const friendRequestSchema = new mongoose.Schema({ const friendRequestSchema = new mongoose.Schema({
customerId: { type: String, default: null }, sender: { type: mongoose.Schema.Types.ObjectId, ref: 'user' },
supplierId: { type: String, default: null }, receiver: { type: mongoose.Schema.Types.ObjectId, ref: 'supplier' },
status: { type: String, default: "pending" }, status: { type: String, default: "pending" },
timestamp: { type: Date, default: Date.now } timestamp: { type: Date, default: Date.now }
}); });

@ -15,11 +15,9 @@ const tankersSchema = new mongoose.Schema({
tankerName: { type: String, default: null }, tankerName: { type: String, default: null },
phoneNumber: { type: String, default: null }, phoneNumber: { type: String, default: null },
alternative_phoneNumber: { type: String, default: null }, alternative_phoneNumber: { type: String, default: null },
typeofwater: { typeofwater: [{ typeofwater: String}],
type: [String], price:[{ typeofwater: String}],
default: [] capacity: { capacity: String},
},
capacity: { type: String},
supplier_address: { type: String, default: null }, supplier_address: { type: String, default: null },
supplier_name : { type: String, default: null }, supplier_name : { type: String, default: null },
price: { price: {

@ -16,8 +16,8 @@ module.exports = function (fastify, opts, next) {
type: "object", type: "object",
//required: ["customerId"], //required: ["customerId"],
properties: { properties: {
customerId: { type: "string" }, senderId: { type: "string" },
supplierId : { type : "string"} receiverId : { type : "string"}
}, },
}, },
security: [ security: [
@ -40,7 +40,7 @@ module.exports = function (fastify, opts, next) {
body: { body: {
type: "object", type: "object",
properties: { properties: {
supplierId: { type: "string" }, friendRequestId: { type: "string" },
}, },
}, },
@ -63,7 +63,7 @@ module.exports = function (fastify, opts, next) {
body: { body: {
type: "object", type: "object",
properties: { properties: {
supplierId: { type: "string" }, friendRequestId: { type: "string" },
}, },
}, },
@ -75,8 +75,6 @@ module.exports = function (fastify, opts, next) {
}, },
handler: validationHandler.friendRequestReject handler: validationHandler.friendRequestReject
}); });
next(); next();
} }

@ -31,7 +31,27 @@ module.exports = function (fastify, opts, next) {
tankerName: { type: "string" }, tankerName: { type: "string" },
phoneNumber: { type: "string"}, phoneNumber: { type: "string"},
alternative_phoneNumber: { type: "string"}, alternative_phoneNumber: { type: "string"},
typeofwater: { type: "string"}, typeofwater: {
type: "array",
maxItems: 2500,
items: {
type: "object",
properties: {
typeofwater: { type: "string", default: null },
},
},
},
price: {
type: "array",
maxItems: 2500,
items: {
type: "object",
properties: {
price: { type: "string", default: null },
},
},
},
capacity: { type: "string"}, capacity: { type: "string"},
price: {type : "string"}, price: {type : "string"},
status: {type: "string"} status: {type: "string"}

Loading…
Cancel
Save