feat: added username field to user and changed routes

This commit is contained in:
Rushil Umaretiya 2021-04-10 13:33:11 -04:00
parent 25cec53f39
commit 33757c6bb9
No known key found for this signature in database
GPG Key ID: 4E8FAF9C926AF959
6 changed files with 45 additions and 9 deletions

View File

@ -22,9 +22,11 @@
"@types/cors": "^2.8.10",
"@types/express": "^4.17.11",
"@types/node": "^14.14.37",
"@types/uuid": "^8.3.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"typescript": "^4.2.4"
"typescript": "^4.2.4",
"uuid": "^8.3.2"
}
}

View File

@ -10,7 +10,22 @@ import {
export const router = Router();
router.get('/user', (req, res) => {
router.get('/user/:userID', (req, res) => {
if (typeof req.query.userID != 'string') {
return;
}
let userID = req.query.userID;
let user = getUserByID(userID);
if (user) {
res.json({ status: 'success', data: user });
} else {
res.json({ status: 'error', error: 'not_found' });
}
});
router.post('/user', (req, res) => {
if (typeof req.query.userID != 'string') {
return;
}
@ -31,6 +46,7 @@ router.post('/user', (req, res) => {
} else {
users[req.body.userID] = {
id: req.body.userID,
username: req.body.username,
first_name: req.body.first_name,
last_name: req.body.last_name,
};

View File

@ -3,7 +3,8 @@
*/
export const users: Record<string, Carpool.User> = {
myfatemi04: {
id: 'myfatemi04',
id: '3baeaed6-05cb-4c03-9b43-1d74beafdbb7',
username: 'myfatemi04',
first_name: 'Michael',
last_name: 'Fatemi',
},

View File

@ -1,10 +1,16 @@
import cors = require('cors');
import express = require('express');
import * as api from './api';
import express from 'express';
import dotenv from 'dotenv';
import cors from 'cors';
import { users, groups } from './data';
dotenv.config({
path: '.env',
});
const app = express();
app.use(cors());
app.use('/api', api.router);
app.use(cors);
app.listen(80, () => void console.log('Listening on port 80'));
((port = process.env.APP_PORT || 5000) => {
app.listen(port, () => void console.log(`Listening on port ${port}`));
})();

View File

@ -6,6 +6,7 @@ namespace Carpool {
export interface User {
id: string;
username: string;
first_name: string;
last_name: string;
}

View File

@ -69,6 +69,11 @@
"@types/mime" "^1"
"@types/node" "*"
"@types/uuid@^8.3.0":
version "8.3.0"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f"
integrity sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==
accepts@~1.3.7:
version "1.3.7"
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd"
@ -452,6 +457,11 @@ utils-merge@1.0.1:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=
uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
vary@^1, vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"