updates to friend route, some changes to ui components, front end api tools
This commit is contained in:
@@ -64,6 +64,16 @@ export default class UserCtl {
|
||||
}
|
||||
}
|
||||
|
||||
async getPendingFriendRequests(senderid: string | number) {
|
||||
try {
|
||||
const { ok, code, result } = await UserInstance.getPendingFriendRequests(senderid);
|
||||
if (ok) return result;
|
||||
throw createError(code, result);
|
||||
} catch (e: any) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async addFriendship(userid: number | string, targetid: number | string) {
|
||||
try {
|
||||
const result = await UserInstance.addFriendship(userid, targetid);
|
||||
|
||||
@@ -123,6 +123,18 @@ export class User {
|
||||
}
|
||||
}
|
||||
|
||||
async getPendingFriendRequests(senderid: number | string) {
|
||||
try {
|
||||
const statement = `SELECT * FROM recipin.cmp_userfriendships WHERE pending = true AND senderid = $1`
|
||||
const result = await pool.query(statement, [senderid]);
|
||||
|
||||
if (result.rows.length) return { ok: true, code: 200, result: result.rows }
|
||||
return { ok: true, code: 200, result: "No pending friend requests found" }
|
||||
} catch (e: any) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async addFriendship(userid: number | string, targetid: number | string) {
|
||||
try {
|
||||
const statement = `
|
||||
|
||||
@@ -23,10 +23,16 @@ export const friendRouter = (app: Express) => {
|
||||
// get all friendships for a user
|
||||
router.get('/', async (req, res, next) => {
|
||||
const { user }: any = req.user;
|
||||
const { pending } = req.query;
|
||||
|
||||
try {
|
||||
const result = await UserInstance.getFriends(user.id);
|
||||
res.status(200).send(result);
|
||||
if (pending) {
|
||||
const result = await UserInstance.getPendingFriendRequests(user.id);
|
||||
res.status(200).send(result);
|
||||
} else {
|
||||
const result = await UserInstance.getFriends(user.id);
|
||||
res.status(200).send(result);
|
||||
}
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user