express-generator-typescript 2.4.11 → 2.4.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/project-files/src/routes/UserRoutes.ts +1 -1
- package/lib/project-files/src/routes/common/types.ts +20 -0
- package/lib/project-files-auth/src/routes/AuthRoutes.ts +1 -1
- package/lib/project-files-auth/src/routes/UserRoutes.ts +1 -1
- package/lib/project-files-auth/src/routes/common/types.ts +49 -0
- package/lib/project-files-auth/src/routes/middleware/adminMw.ts +5 -9
- package/package.json +1 -1
- package/lib/project-files/src/routes/types/express/index.d.ts +0 -11
- package/lib/project-files/src/routes/types/express/misc.ts +0 -12
- package/lib/project-files/src/routes/types/types.ts +0 -14
- package/lib/project-files-auth/src/routes/types/express/index.d.ts +0 -11
- package/lib/project-files-auth/src/routes/types/express/misc.ts +0 -16
- package/lib/project-files-auth/src/routes/types/types.ts +0 -22
|
@@ -2,7 +2,7 @@ import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
|
2
2
|
|
|
3
3
|
import UserService from '@src/services/UserService';
|
|
4
4
|
import { IUser } from '@src/models/User';
|
|
5
|
-
import { IReq, IRes } from './types
|
|
5
|
+
import { IReq, IRes } from './common/types';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
// **** Functions **** //
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
/**
|
|
3
|
+
* Shared types for routes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Response, Request } from 'express';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// **** Express **** //
|
|
10
|
+
|
|
11
|
+
type TPathParams = Record<string, string>;
|
|
12
|
+
|
|
13
|
+
export interface IReq<T = void> extends Request<TPathParams, void, T, TPathParams> {
|
|
14
|
+
body: T;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IRes extends Response {
|
|
18
|
+
locals: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
|
|
@@ -2,7 +2,7 @@ import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
|
2
2
|
import SessionUtil from '@src/util/SessionUtil';
|
|
3
3
|
import AuthService from '@src/services/AuthService';
|
|
4
4
|
|
|
5
|
-
import { IReq, IRes } from './types
|
|
5
|
+
import { IReq, IRes } from './common/types';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
// **** Types **** //
|
|
@@ -2,7 +2,7 @@ import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
|
2
2
|
|
|
3
3
|
import UserService from '@src/services/UserService';
|
|
4
4
|
import { IUser } from '@src/models/User';
|
|
5
|
-
import { IReq, IRes } from './types
|
|
5
|
+
import { IReq, IRes } from './common/types';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
// **** Functions **** //
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// import * as e from 'express';
|
|
2
|
+
// import { Query } from 'express-serve-static-core';
|
|
3
|
+
|
|
4
|
+
// import { ISessionUser } from '@src/models/User';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// // **** Express **** //
|
|
8
|
+
|
|
9
|
+
// export interface IReq<T = void> extends e.Request {
|
|
10
|
+
// body: T;
|
|
11
|
+
// }
|
|
12
|
+
|
|
13
|
+
// export interface IReqQuery<T extends Query, U = void> extends e.Request {
|
|
14
|
+
// query: T;
|
|
15
|
+
// body: U;
|
|
16
|
+
// }
|
|
17
|
+
|
|
18
|
+
// export interface IRes extends e.Response {
|
|
19
|
+
// locals: {
|
|
20
|
+
// sessionUser: ISessionUser;
|
|
21
|
+
// };
|
|
22
|
+
// }
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/* eslint-disable max-len */
|
|
26
|
+
/**
|
|
27
|
+
* Shared types for routes.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { Response, Request } from 'express';
|
|
31
|
+
import { ISessionUser } from '@src/models/User';
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// **** Express **** //
|
|
35
|
+
|
|
36
|
+
type TPathParams = Record<string, string>;
|
|
37
|
+
|
|
38
|
+
export interface IReq<T = void> extends Request<TPathParams, void, T, TPathParams> {
|
|
39
|
+
body: T;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface ILocals {
|
|
43
|
+
sessionUser: ISessionUser;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// I know since its a type I should use 'TRes' instead of 'IRes' but I'm
|
|
47
|
+
// leaving it as this cause it looks better alongside 'IReq'
|
|
48
|
+
export type IRes = Response<unknown, ILocals>;
|
|
49
|
+
|
|
@@ -2,33 +2,29 @@
|
|
|
2
2
|
* Middleware to verify user logged in and is an an admin.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { NextFunction } from 'express';
|
|
6
6
|
import { JwtPayload } from 'jsonwebtoken';
|
|
7
7
|
|
|
8
8
|
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
9
|
-
|
|
10
9
|
import SessionUtil from '@src/util/SessionUtil';
|
|
11
10
|
import { ISessionUser, UserRoles } from '@src/models/User';
|
|
12
11
|
|
|
12
|
+
import { IReq, IRes } from '../common/types';
|
|
13
|
+
|
|
13
14
|
|
|
14
15
|
// **** Variables **** //
|
|
15
16
|
|
|
16
17
|
const USER_UNAUTHORIZED_ERR = 'User not authorized to perform this action';
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
// **** Types **** //
|
|
20
|
-
|
|
21
19
|
type TSessionData = ISessionUser & JwtPayload;
|
|
22
20
|
|
|
23
21
|
|
|
24
|
-
// **** Functions **** //
|
|
25
|
-
|
|
26
22
|
/**
|
|
27
23
|
* See note at beginning of file.
|
|
28
24
|
*/
|
|
29
25
|
async function adminMw(
|
|
30
|
-
req:
|
|
31
|
-
res:
|
|
26
|
+
req: IReq,
|
|
27
|
+
res: IRes,
|
|
32
28
|
next: NextFunction,
|
|
33
29
|
) {
|
|
34
30
|
// Get session data
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.14",
|
|
4
4
|
"description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"express-generator-typescript": "node bin/cli.js",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as e from 'express';
|
|
2
|
-
import { Query } from 'express-serve-static-core';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// **** Express **** //
|
|
6
|
-
|
|
7
|
-
export interface IReq<T = void> extends e.Request {
|
|
8
|
-
body: T;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface IReqQuery<T extends Query, U = void> extends e.Request {
|
|
12
|
-
query: T;
|
|
13
|
-
body: U;
|
|
14
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as e from 'express';
|
|
2
|
-
|
|
3
|
-
import { ISessionUser } from '@src/models/User';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// **** Express **** //
|
|
7
|
-
|
|
8
|
-
export interface IReq<T = void> extends e.Request {
|
|
9
|
-
body: T;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface IRes extends e.Response {
|
|
13
|
-
locals: {
|
|
14
|
-
sessionUser?: ISessionUser;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as e from 'express';
|
|
2
|
-
import { Query } from 'express-serve-static-core';
|
|
3
|
-
|
|
4
|
-
import { ISessionUser } from '@src/models/User';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// **** Express **** //
|
|
8
|
-
|
|
9
|
-
export interface IReq<T = void> extends e.Request {
|
|
10
|
-
body: T;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface IReqQuery<T extends Query, U = void> extends e.Request {
|
|
14
|
-
query: T;
|
|
15
|
-
body: U;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface IRes extends e.Response {
|
|
19
|
-
locals: {
|
|
20
|
-
sessionUser: ISessionUser;
|
|
21
|
-
};
|
|
22
|
-
}
|