diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index 9f36d0f1..43f7fc00 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -60,7 +60,6 @@ console.log(req.params); tankers.alternative_phoneNumber = usertobeInserted.alternative_phoneNumber; tankers.capacity = usertobeInserted.capacity; tankers.typeofwater = usertobeInserted.typeofwater; - tankers.supplierId = usertobeInserted.supplierId; tankers.price = usertobeInserted.price; tankers.status = usertobeInserted.status; } diff --git a/src/handlers/friendRequestHandler.js b/src/handlers/friendRequestHandler.js index 7010ae93..3c09331b 100644 --- a/src/handlers/friendRequestHandler.js +++ b/src/handlers/friendRequestHandler.js @@ -14,10 +14,10 @@ exports.friendRequest = async (request, reply) => { const { senderId, receiverId } = request.body; // Check if the sender and receiver exist in the database - const sender = await User.findOne(senderId); - const receiver = await Supplier.findOne(receiverId); - console.log("sender" , sender.customerId) - console.log("receiver" , receiver.supplierId) + const sender = await User.findById(senderId); + const receiver = await Supplier.findById(receiverId); + console.log("sender" , sender) + console.log("receiver" , receiver) if (!sender || !receiver) { @@ -25,21 +25,22 @@ exports.friendRequest = async (request, reply) => { } // Check if a friend request already exists between the two users - const existingRequest = await FriendRequest.findOne({ customerId: sender.customerId, supplierId: receiver.supplierId}); - - console.log(existingRequest, " .. exist") + const existingRequest = await FriendRequest.findOne({ sender: senderId, receiver: receiverId }); if (existingRequest) { throw new Error('Friend request already sent'); } // 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(); console.log("friendRequest", friendRequest) - reply.send({ message: 'Friend request sent' }); + reply.send({ message: 'Friend request sent' }); } catch (err) { reply.status(400).send({ error: err.message }); } @@ -48,10 +49,10 @@ exports.friendRequest = async (request, reply) => { // Handle friend request acceptance exports.friendRequestAccept = async (request, reply) => { try { - const {supplierId} = request.body; + const {friendRequestId} = request.body; // 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) @@ -69,10 +70,10 @@ exports.friendRequestAccept = async (request, reply) => { // Handle friend request rejection exports.friendRequestReject = async (request, reply) => { try { - const {supplierId} = request.body; + const {friendRequestId} = request.body; - // Update the friend request status to 'reject' - const friendRequest = await FriendRequest.findOneAndUpdate({supplierId}, { status: 'rejected' }); + // Update the friend request status to 'rejected' + const friendRequest = await FriendRequest.findByIdAndUpdate(friendRequestId, { status: 'rejected' }); console.log("friendRequest....---", friendRequest) diff --git a/src/models/supplier.js b/src/models/supplier.js index c6c560a8..b0cbd46a 100644 --- a/src/models/supplier.js +++ b/src/models/supplier.js @@ -94,8 +94,8 @@ const supplierSchema = new mongoose.Schema( // }) const friendRequestSchema = new mongoose.Schema({ - customerId: { type: String, default: null }, - supplierId: { type: String, default: null }, + sender: { type: mongoose.Schema.Types.ObjectId, ref: 'user' }, + receiver: { type: mongoose.Schema.Types.ObjectId, ref: 'supplier' }, status: { type: String, default: "pending" }, timestamp: { type: Date, default: Date.now } }); diff --git a/src/models/tankers.js b/src/models/tankers.js index bf8e8efb..6c0b6c9f 100644 --- a/src/models/tankers.js +++ b/src/models/tankers.js @@ -15,11 +15,9 @@ const tankersSchema = new mongoose.Schema({ tankerName: { type: String, default: null }, phoneNumber: { type: String, default: null }, alternative_phoneNumber: { type: String, default: null }, - typeofwater: { - type: [String], - default: [] - }, - capacity: { type: String}, + typeofwater: [{ typeofwater: String}], + price:[{ typeofwater: String}], + capacity: { capacity: String}, supplier_address: { type: String, default: null }, supplier_name : { type: String, default: null }, price: { diff --git a/src/routes/friendRequestRoute.js b/src/routes/friendRequestRoute.js index 65a873f2..b92a2455 100644 --- a/src/routes/friendRequestRoute.js +++ b/src/routes/friendRequestRoute.js @@ -16,8 +16,8 @@ module.exports = function (fastify, opts, next) { type: "object", //required: ["customerId"], properties: { - customerId: { type: "string" }, - supplierId : { type : "string"} + senderId: { type: "string" }, + receiverId : { type : "string"} }, }, security: [ @@ -40,7 +40,7 @@ module.exports = function (fastify, opts, next) { body: { type: "object", properties: { - supplierId: { type: "string" }, + friendRequestId: { type: "string" }, }, }, @@ -63,7 +63,7 @@ module.exports = function (fastify, opts, next) { body: { type: "object", properties: { - supplierId: { type: "string" }, + friendRequestId: { type: "string" }, }, }, @@ -75,8 +75,6 @@ module.exports = function (fastify, opts, next) { }, handler: validationHandler.friendRequestReject }); - - next(); } diff --git a/src/routes/tankersRoute.js b/src/routes/tankersRoute.js index c5ed7755..c0ca27db 100644 --- a/src/routes/tankersRoute.js +++ b/src/routes/tankersRoute.js @@ -31,7 +31,27 @@ module.exports = function (fastify, opts, next) { tankerName: { type: "string" }, 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"}, price: {type : "string"}, status: {type: "string"}