Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Allow, Email, MinLength, Property, Required} from "@tsed/common";
import {Hidden} from "@tsed/swagger";
import {Indexed, Model, Unique} from "../../../../packages/mongoose/src/decorators";
export interface IUser {
name: string;
email: string;
password: string;
}
@Hidden()
@Model()
export class User {
@Property()
name: string;
@Indexed()
@Required()
@Email()
@Unique()
@Allow(null)
email: string;
@Required()
@MinLength(6)
@Allow(null)
password: string;
import {ContentType, Controller, Get, Next, PathParams, Post, Req, Res, Status} from "@tsed/common";
import {Docs, Hidden} from "@tsed/swagger";
import {createReadStream} from "fs";
import {join} from "path";
import {of} from "rxjs";
@Controller("/response")
@Hidden()
@Docs("responses")
export class ResponseScenarioCtrl {
@Get("/scenario1/:id")
public testScenario1Assert(@PathParams("id") id: number, @Req() request: Req) {
request.ctx.test = "value";
}
@Get("/scenario1/:id")
public testScenario1Get(@PathParams("id") id: number, @Req() request: Req) {
return id + request.ctx.test;
}
@Get("/scenario2/:id")
public testScenario2Assert(@PathParams("id") id: number, @Req() request: Req, @Next() next: Next) {
setTimeout(() => {
import {BodyParams, Controller, Get, Post, Scope} from "@tsed/common";
import {Docs, Hidden} from "@tsed/swagger";
import {$log} from "ts-log-debug";
import {CalendarModel} from "../../models/Calendar";
import {AdminProductPostModel, UserProductPostModel} from "../../models/Product";
import {InnerService} from "../../services/InnerService";
import {OuterService} from "../../services/OuterService";
@Controller("/products")
@Scope("request")
@Hidden()
@Docs("hidden")
export class ProductsCtrl {
constructor(public innerService: InnerService, public outerService: OuterService) {
$log.debug("Controller New Instance");
$log.debug("innerService == outerService.innerService? ", innerService === outerService.innerService);
}
@Get("/")
async renderCalendars(): Promise {
return [{id: "1", name: "test"}];
}
$onDestroy() {
$log.debug("Destroy controller");
}
import {ContentType, Controller, Get, Render} from "@tsed/common";
import {Hidden} from "@tsed/swagger";
import * as fs from "fs";
@Controller("/")
@Hidden()
export class SocketPageCtrl {
@Get("/socket")
@Render("socket")
public socket() {
return {socketScript: "/socket/socket.io.js"};
}
@Get("/socket/socket.io.js")
@ContentType("application/javascript")
public getScript() {
return fs.readFileSync(require.resolve("socket.io-client/dist/socket.io.js"), {encoding: "utf8"});
}
}