-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
29 lines (22 loc) · 1010 Bytes
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import express from "express";
import { DataStore } from "./data/data";
import { apiGetUsers } from "./api/apiGetUsers";
import { apiGetUsersDetails } from "./api/apiGetUserDetails";
import { apiGetUserEventsForDay } from "./api/apiGetUseEventsForDay";
import * as bodyparser from "body-parser";
import { apiCreateUser } from "./api/apiCreateUser";
const { check, validationResult } = require('express-validator/check');
const jsonParser = bodyparser.json();
const app = express();
//console.log(JSON.parse(JSON.stringify(DataStore.users)));
app.get("/users", apiGetUsers);
app.get("/users/:id", apiGetUsersDetails);
app.get("/events/user/day", apiGetUserEventsForDay);
app.get("/events/user/:userid", apiGetUserEventsForDay);
app.post("/users", jsonParser,[
// email must be an email
check('email').isEmail(),
check('password').not().isEmpty(),
check('phone').isMobilePhone().optional()
], apiCreateUser);
app.listen(process.env.PORT || 8091 , ()=> {console.log("Server started ...")});