-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from AarshShah9/Aarsh/Tags
DRAFT
- Loading branch information
Showing
17 changed files
with
194 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { RequestExtended } from "../middleware/verifyAuth"; | ||
import { Response, NextFunction } from "express"; | ||
import prisma from "../prisma/client"; | ||
import { AppError, AppErrorName } from "../utils/AppError"; | ||
|
||
export const getAllTags = async ( | ||
req: RequestExtended, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
try { | ||
const tags = await prisma.topic.findMany({ | ||
select: { | ||
topicName: true, | ||
}, | ||
}); | ||
|
||
if (!tags) { | ||
throw new AppError(AppErrorName.NOT_FOUND_ERROR, "Tags not found", 404); | ||
} | ||
|
||
res.status(200).json({ | ||
data: { tags: tags.map((tag) => tag.topicName) }, | ||
message: "Tags fetched successfully", | ||
}); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const getUserSubscriptions = async ( | ||
req: RequestExtended, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
// modify during integration | ||
const loggedInUserId = req.body.userId; | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
id: loggedInUserId, | ||
}, | ||
include: { | ||
subscriptions: { | ||
include: { | ||
topic: { | ||
select: { | ||
id: true, | ||
topicName: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!user) { | ||
throw new AppError(AppErrorName.NOT_FOUND_ERROR, "User not found", 404); | ||
} | ||
|
||
res.status(200).json({ | ||
topics: user.subscriptions.map((sub) => { | ||
return { | ||
id: sub.topic.id, | ||
name: sub.topic.topicName, | ||
}; | ||
}), | ||
}); | ||
}; | ||
|
||
export const modifyUserTags = async ( | ||
req: RequestExtended, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
// modify during integration | ||
const loggedInUserId = req.body.userId; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import express from "express"; | ||
import { | ||
getAllTags, | ||
modifyUserTags, | ||
getUserSubscriptions, | ||
} from "../controllers/tag.controller"; | ||
import { verifyAuthentication } from "../middleware/verifyAuth"; | ||
|
||
const router = express.Router(); | ||
|
||
router.use(verifyAuthentication); | ||
router.get("/getAllTags", getAllTags); | ||
router.get("/readUserTags", getUserSubscriptions); | ||
router.post("/modifyUserTags", modifyUserTags); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters