diff --git a/packages/api/routes/contacts.ts b/packages/api/routes/contacts.ts index 5c73c15..79f3fdb 100644 --- a/packages/api/routes/contacts.ts +++ b/packages/api/routes/contacts.ts @@ -93,7 +93,7 @@ async function updateRelationshipState(req: Request, res: Response) { requestObj.newState ); - updateResult?.acknowledged + updateResult?.modifiedCount ? res.status(200).send("Updated state of relationship") : res.status(500).send("Failed to update relationship"); diff --git a/packages/api/services/contact.service.ts b/packages/api/services/contact.service.ts index c41f7d9..2ae1c0e 100644 --- a/packages/api/services/contact.service.ts +++ b/packages/api/services/contact.service.ts @@ -20,8 +20,8 @@ export class ContactService { // i could also be the receiver and them the sender const clauseTwo = { $and: [ - { senderUserId: myGoogleUserId }, - { receiverUserId: otherGoogleUserId }, + { senderUserId: otherGoogleUserId }, + { receiverUserId: myGoogleUserId }, ], }; @@ -58,8 +58,12 @@ export class ContactService { relationshipId: ObjectId, newState: RelationshipState ) { - const query = { _id: relationshipId }; - const updateDoc = { $set: { state: newState } }; + const query = { _id: new ObjectId(relationshipId) }; + console.log(newState); + console.log(relationshipId); + const updateDoc = { + $set: { state: newState, lastUpdatedDate: new Date() }, + }; const result = await collections.relationships?.updateOne(query, updateDoc); return result;