Skip to content

Commit

Permalink
chore: update to tsed
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Dec 18, 2023
1 parent 7e4d384 commit 7c6a925
Show file tree
Hide file tree
Showing 6 changed files with 2,575 additions and 1,586 deletions.
85 changes: 42 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "yarn run barrels && yarn run tsc --project tsconfig.compile.json",
"barrels": "barrelsby --config .barrelsby.json",
"start": "yarn run barrels && tsnd --inspect --ignore-watch node_modules --respawn --transpile-only -r tsconfig-paths/register src/index.ts",
"start": "tsnd --inspect --ignore-watch node_modules --respawn --transpile-only src/index.ts",
"start:prod": "cross-env NODE_ENV=production node dist/index.js",
"test": "yarn run test:lint && yarn run test:coverage",
"test:unit": "cross-env NODE_ENV=test jest",
Expand All @@ -19,27 +19,27 @@
"author": "",
"license": "MIT",
"dependencies": {
"@tsed/ajv": "^6.114.14",
"@tsed/adapters": "^6.114.14",
"@tsed/common": "^6.114.14",
"@tsed/core": "^6.114.14",
"@tsed/di": "^6.114.14",
"@tsed/engines": "^6.114.14",
"@tsed/exceptions": "^6.114.14",
"@tsed/json-mapper": "^6.114.14",
"@tsed/ajv": "7.52.0",
"@tsed/adapters": "7.52.0",
"@tsed/common": "7.52.0",
"@tsed/core": "7.52.0",
"@tsed/di": "7.52.0",
"@tsed/engines": "7.52.0",
"@tsed/exceptions": "7.52.0",
"@tsed/json-mapper": "7.52.0",
"@tsed/logger": "^6.1.1",
"@tsed/logger-file": "^6.1.1",
"@tsed/passport": "^6.114.14",
"@tsed/platform-cache": "^6.114.14",
"@tsed/platform-exceptions": "^6.114.14",
"@tsed/platform-express": "^6.114.14",
"@tsed/platform-log-middleware": "^6.114.14",
"@tsed/platform-middlewares": "^6.114.14",
"@tsed/platform-params": "^6.114.14",
"@tsed/platform-response-filter": "^6.114.14",
"@tsed/platform-views": "^6.114.14",
"@tsed/schema": "^6.114.14",
"@tsed/swagger": "^6.114.14",
"@tsed/passport": "7.52.0",
"@tsed/platform-cache": "7.52.0",
"@tsed/platform-exceptions": "7.52.0",
"@tsed/platform-express": "7.52.0",
"@tsed/platform-log-middleware": "7.52.0",
"@tsed/platform-middlewares": "7.52.0",
"@tsed/platform-params": "7.52.0",
"@tsed/platform-response-filter": "7.52.0",
"@tsed/platform-views": "7.52.0",
"@tsed/schema": "7.52.0",
"@tsed/swagger": "7.52.0",
"ajv": "^8.11.0",
"barrelsby": "^2.3.4",
"body-parser": "^1.20.0",
Expand All @@ -61,11 +61,11 @@
"passport-http": "^0.3.0"
},
"devDependencies": {
"@tsed/cli-plugin-eslint": "3.20.8",
"@tsed/cli-plugin-jest": "3.20.8",
"@tsed/cli-plugin-mongoose": "3.20.8",
"@tsed/cli-plugin-passport": "3.20.8",
"@tsed/testing-mongoose": "^6.114.14",
"@tsed/cli-plugin-eslint": "4.6.6",
"@tsed/cli-plugin-jest": "4.6.6",
"@tsed/cli-plugin-mongoose": "4.6.6",
"@tsed/cli-plugin-passport": "4.6.6",
"@tsed/testing-mongoose": "7.52.0",
"@types/compression": "^1.7.2",
"@types/cookie-parser": "^1.4.2",
"@types/cors": "^2.8.12",
Expand All @@ -79,24 +79,23 @@
"@types/passport-local": "^1.0.34",
"@types/passport-http": "^0.3.9",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"@types/lodash": "^4.14.182",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"is-ci": "^3.0.1",
"jest": "^28.0.1",
"lint-staged": "^12.4.0",
"prettier": "^2.6.2",
"supertest": "^6.2.2",
"ts-jest": "^28.0.3",
"ts-node": "^10.7.0",
"ts-node-dev": "^1.1.8",
"tsconfig-paths": "^3.14.1",
"tslib": "^2.4.0",
"typescript": "^4.6.3"
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@types/lodash": "4.14.202",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.0.1",
"husky": "8.0.3",
"is-ci": "3.0.1",
"jest": "29.7.0",
"lint-staged": "15.2.0",
"prettier": "3.1.1",
"supertest": "6.3.3",
"ts-jest": "29.1.1",
"ts-node": "10.9.2",
"ts-node-dev": "2.0.0",
"tslib": "2.6.2",
"typescript": "5.3.3"
},
"tsed": {
"packageManager": "yarn",
Expand Down
47 changes: 24 additions & 23 deletions src/Server.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { Configuration } from "@tsed/di";
import {Configuration} from "@tsed/di";
import "@tsed/platform-express"; // /!\ keep this import
import "@tsed/ajv";
import "@tsed/swagger";
import "@tsed/passport";
import compress from "compression";
import cookieParser from "cookie-parser";
import methodOverride from "method-override";
import cors from "cors";
import session from "express-session";
import { config } from "./config";
import {config} from "./config";
import * as rest from "./controllers/rest";
import * as pages from "./controllers/pages";
import "./protocols";
Expand All @@ -24,22 +19,28 @@ import "./protocols";
"/": [...Object.values(pages)]
},
middlewares: [
cors(),
cookieParser(),
compress({}),
methodOverride(),
session({
secret: "mysecretkey",
resave: true,
saveUninitialized: true,
// maxAge: 36000,
cookie: {
path: "/",
httpOnly: true,
secure: false
// maxAge: null
"cors",
"cookie-parser",
"compression",
"method-override",
"json-parser",
{use: "urlencoded-parser", options: {extended: true}},
{
use: "express-session",
options: {
secret: "mysecretkey",
resave: true,
saveUninitialized: true,
// maxAge: 36000,
cookie: {
path: "/",
httpOnly: true,
secure: false
// maxAge: null
}
}
})
}
]
})
export class Server {}
export class Server {
}
24 changes: 12 additions & 12 deletions src/controllers/rest/passport/PassportCtrl.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { BodyParams, Controller, Get, Post, Req } from "@tsed/common";
import { Authenticate, Authorize } from "@tsed/passport";
import { Credentials } from "../../../models/Credentials";
import { User } from "../../../models/User";
import { UserCreation } from "../../../models/UserCreation";
import { Returns, Security } from "@tsed/schema";
import {BodyParams, Controller, Get, Post, Req} from "@tsed/common";
import {Authenticate, Authorize} from "@tsed/passport";
import {Credentials} from "../../../models/Credentials";
import {User} from "../../../models/User";
import {UserCreation} from "../../../models/UserCreation";
import {Groups, Returns, Security} from "@tsed/schema";

@Controller("/auth")
export class PassportCtrl {
@Post("/login")
@Authenticate("login", { failWithError: false })
@Returns(200, User)
@Authenticate("login", {failWithError: false})
@Returns(200, User).Groups("read")
@Returns(400).Description("Validation error")
// eslint-disable-next-line @typescript-eslint/no-unused-vars
login(@Req() req: Req, @BodyParams() credentials: Credentials) {
login(@Req() req: Req, @BodyParams() @Groups("credentials") credentials: Credentials) {
// FACADE
return req.user;
}

@Post("/signup")
@Returns(201, User)
@Returns(201, User).Groups("read")
@Authenticate("signup")
// eslint-disable-next-line @typescript-eslint/no-unused-vars
signup(@Req() req: Req, @BodyParams() user: UserCreation) {
signup(@Req() req: Req, @BodyParams() @Groups("create") user: UserCreation) {
// FACADE
return req.user;
}

@Get("/userinfo")
@Authenticate("basic")
@Security("auth:basic")
@Returns(200, User)
@Returns(200, User).Groups("read")
getUserInfo(@Req() req: Req) {
// FACADE
return req.user;
Expand Down
3 changes: 2 additions & 1 deletion src/models/Credentials.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Description, Example, Format, Required } from "@tsed/schema";
import {Description, Example, Format, Groups, Required} from "@tsed/schema";

export class Credentials {
@Description("User password")
@Example("/5gftuD/")
@Required()
@Groups("create", "update", "credentials")
password: string;

@Description("User email")
Expand Down
7 changes: 2 additions & 5 deletions src/models/User.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Description, Ignore } from "@tsed/schema";
import { UserCreation } from "./UserCreation";
import {Description} from "@tsed/schema";
import {UserCreation} from "./UserCreation";

export class User extends UserCreation {
@Description("Database assigned id")
_id: string;

@Ignore()
declare password: string;

verifyPassword(password: string) {
return this.password === password;
}
Expand Down
Loading

0 comments on commit 7c6a925

Please sign in to comment.