requests for user data on ui
This commit is contained in:
@@ -92,7 +92,11 @@ export class User {
|
||||
|
||||
async getFriends(id: number | string) {
|
||||
try {
|
||||
const sql = fs.readFileSync(appRoot + '/db/sql/derived/friendships.sql').toString();
|
||||
// const sql = fs.readFileSync(appRoot + '/db/sql/derived/friendships.sql').toString();
|
||||
const sql = `
|
||||
SELECT * FROM recipin.cmp_userfriendships
|
||||
WHERE senderid = $1;
|
||||
`
|
||||
const result = await pool.query(sql, [id]);
|
||||
if (result.rows.length) return result.rows;
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Express, Router } from 'express';
|
||||
import UserCtl from '../controllers/UserCtl';
|
||||
import { IUser } from '../schemas';
|
||||
const router = Router();
|
||||
const userCtl = new UserCtl();
|
||||
|
||||
@@ -13,11 +14,18 @@ export const userRoute = (app: Express) => {
|
||||
})
|
||||
|
||||
// get, put by id
|
||||
router.get('/:id', async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
router.get('/:userid', async (req, res, next) => {
|
||||
const { userid } = req.params;
|
||||
try {
|
||||
const result = await userCtl.getOne(id);
|
||||
res.status(200).send(result);
|
||||
const result: IUser = await userCtl.getOne(userid);
|
||||
const { email, id, firstname, lastname, handle } = result;
|
||||
res.status(200).send({
|
||||
id: id,
|
||||
email: email,
|
||||
firstname: firstname,
|
||||
lastname: lastname,
|
||||
handle: handle
|
||||
});
|
||||
} catch(e) {
|
||||
next(e);
|
||||
}
|
||||
|
||||
@@ -49,4 +49,10 @@ export interface ICollection extends HasHistory, CanDeactivate {
|
||||
export interface IGroceryList extends HasHistory, CanDeactivate {
|
||||
name: string
|
||||
ownerid: string | number
|
||||
}
|
||||
|
||||
export interface IFriendship extends HasHistory, CanDeactivate {
|
||||
senderid: string | number
|
||||
targetid: string | number
|
||||
pending: boolean
|
||||
}
|
||||
Reference in New Issue
Block a user