Bhaskara Kishore 3 years ago
commit 33a6689dad

@ -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;
}

@ -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)

@ -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 }
});

@ -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: {

@ -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();
}

@ -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"}

Loading…
Cancel
Save