working send request and such
This commit is contained in:
@@ -5,6 +5,7 @@ import express, { Application, Request, Response } from "express";
|
||||
|
||||
import { ContactService } from "../services/contact.service";
|
||||
import { ObjectId } from "mongodb";
|
||||
import UpdateRelationshipStateRequest from "../../core/requests/updateRelationshipState.request";
|
||||
import { authCheck } from "../middleware/auth";
|
||||
import { collections } from "../services/database.service";
|
||||
|
||||
@@ -19,6 +20,8 @@ export default function getContactsRoutes() {
|
||||
// send a friend request
|
||||
router.post("/:otherUserGoogleId", authCheck, addContact);
|
||||
|
||||
router.put("/", authCheck, updateRelationshipState);
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -79,3 +82,23 @@ async function addContact(req: Request, res: Response) {
|
||||
res.status(500).send(`something went wrong`);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateRelationshipState(req: Request, res: Response) {
|
||||
try {
|
||||
// get the userId of the person to add as a friend/contact
|
||||
const requestObj = req.body as UpdateRelationshipStateRequest;
|
||||
|
||||
const updateResult = await ContactService.updateRelationshipState(
|
||||
requestObj.relationshipId,
|
||||
requestObj.newState
|
||||
);
|
||||
|
||||
updateResult?.acknowledged
|
||||
? res.status(200).send("Updated state of relationship")
|
||||
: res.status(500).send("Failed to update relationship");
|
||||
|
||||
return;
|
||||
} catch (error) {
|
||||
res.status(500).send(`something went wrong`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Db } from "mongodb";
|
||||
import Relationship from "@nirvana/core/models/relationship.model";
|
||||
import { Db, ObjectId } from "mongodb";
|
||||
import Relationship, {
|
||||
RelationshipState,
|
||||
} from "@nirvana/core/models/relationship.model";
|
||||
|
||||
import { collections } from "./database.service";
|
||||
|
||||
export class ContactService {
|
||||
@@ -50,4 +53,15 @@ export class ContactService {
|
||||
|
||||
return insertResult;
|
||||
}
|
||||
|
||||
static async updateRelationshipState(
|
||||
relationshipId: ObjectId,
|
||||
newState: RelationshipState
|
||||
) {
|
||||
const query = { _id: relationshipId };
|
||||
const updateDoc = { $set: { state: newState } };
|
||||
const result = await collections.relationships?.updateOne(query, updateDoc);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user