Skip to content

Commit 832e36b

Browse files
atvaneksophia-bui
andcommitted
Adding interfaces to controllers
Co-authored-by: Sophia Bui <[email protected]>
1 parent 50217e1 commit 832e36b

File tree

5 files changed

+201
-167
lines changed

5 files changed

+201
-167
lines changed
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
const cookieController = {};
1+
import { Request, Response, NextFunction } from 'express';
2+
interface CookieController {
3+
setSSIDCookie: (req: Request, res: Response, next: NextFunction) => void;
4+
}
25

3-
// setSSIDCookie - store the user id from database in cookie
4-
cookieController.setSSIDCookie = (req, res, next) => {
5-
// set cookie with key 'ssid' and value to user's id
6-
res.cookie('ssid', res.locals.id, {
7-
httpOnly: true,
8-
sameSite: 'None',
9-
secure: true
10-
});
11-
return next();
12-
};
6+
const cookieController: CookieController = {
7+
8+
// setSSIDCookie - store the user id from database in cookie
9+
setSSIDCookie: (req, res, next) => {
10+
// set cookie with key 'ssid' and value to user's id
11+
res.cookie('ssid', res.locals.id, {
12+
httpOnly: true,
13+
sameSite: 'none',
14+
secure: true
15+
});
16+
return next();
17+
}
18+
}
1319

1420
export default cookieController;

server/controllers/projectController.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { Projects } from '../models/reactypeModels';
2+
import { Request, Response, NextFunction } from 'express';
23

3-
const projectController = {};
4+
interface ProjectController {
5+
saveProject: (req: Request, res: Response, next: NextFunction) => void;
6+
getProjects: (req: Request, res: Response, next: NextFunction) => void;
7+
deleteProject: (req: Request, res: Response, next: NextFunction) => void;
8+
}
9+
10+
const projectController: ProjectController = {
411

512
// saveProject saves current workspace to database
6-
projectController.saveProject = (req, res, next) => {
13+
saveProject: (req, res, next) => {
714
// pull project name and project itself from body
815
const { name, project, userId, username, comments } = req.body;
916
// create createdBy field for the document
@@ -31,10 +38,10 @@ projectController.saveProject = (req, res, next) => {
3138
return next();
3239
}
3340
);
34-
};
41+
},
3542

3643
// gets all of current user's projects
37-
projectController.getProjects = (req, res, next) => {
44+
getProjects: (req, res, next) => {
3845
const { userId } = req.body;
3946
Projects.find({ userId }, (err, projects) => {
4047
if (err) {
@@ -49,10 +56,10 @@ projectController.getProjects = (req, res, next) => {
4956
res.locals.projects = projects.map((elem) => elem.project);
5057
return next();
5158
});
52-
};
59+
},
5360

5461
// delete project from database **currently not integrated into app**
55-
projectController.deleteProject = (req, res, next) => {
62+
deleteProject: (req, res, next) => {
5663
// pull project name and userId from req.body
5764
const { name, userId } = req.body;
5865
Projects.findOneAndDelete({ name, userId }, (err, deleted) => {
@@ -67,6 +74,6 @@ projectController.deleteProject = (req, res, next) => {
6774
res.locals.deleted = deleted;
6875
return next();
6976
});
70-
};
71-
77+
},
78+
}
7279
export default projectController;

0 commit comments

Comments
 (0)