Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { GraphQLResolver, Service } from '@foal/core';
@Service()
export class TestFooBarResolver extends GraphQLResolver {
}
import {
log,
methodNotAllowed,
NotFoundError,
ObjectType,
preHook,
RestController,
Service
} from '@foal/core';
@Service()
@log('User (1)')
@log('User (2)')
export class User implements RestController {
constructor() {}
public async create(data: any, query: ObjectType): Promise {
console.log(data);
return 1;
}
@preHook(ctx => {
console.log(ctx);
})
public async get(id: any, query: ObjectType): Promise {
throw new NotFoundError();
}
describe('view', () => {
@Service()
class MockService implements IView {
constructor() {}
public async render(locals: { name: string }): Promise {
return locals.name || 'bar';
}
}
it('should be an instance of ViewControllerFactory.', () => {
expect(view).to.an.instanceOf(ViewControllerFactory);
});
describe('when attachService is called', () => {
it('should return a controller with a proper "main" route.', async () => {
const controller = view.attachService('/foobar', MockService);
const actual = controller.getRoute('main');
import { Request, Response } from 'express';
import { BasicController, Service } from '@foal/core';
import { MyController } from '../services/my-controller.controller';
@Service()
export class TotoController implements BasicController {
constructor(private myController: MyController) {}
public post(req: Request, res: Response) {
console.log(this.myController.foobar);
this.myController.foobar = 'toto';
res.send('Yeah man!');
}
public get(req: Request, res: Response) {
}
public put(req: Request, res: Response) {
}
import { Service } from '@foal/core';
import { EjsTemplateService } from '@foal/ejs';
@Service()
export class LoginViewService extends EjsTemplateService {
constructor() {
super('./templates/login.html');
}
}
import { Service } from '@foal/core';
import { SequelizeConnectionService } from '@foal/sequelize';
import { config } from '../../config';
@Service()
export class ConnectionService extends SequelizeConnectionService {
constructor() {
super(config.db.uri);
}
}
import { Service } from '@foal/core';
import { Sequelize, SequelizeConnectionService, SequelizeService } from '@foal/sequelize';
export interface User {
firstName: string;
lastName: string;
}
@Service()
export class Connection extends SequelizeConnectionService {
constructor() {
super('postgres://postgres:LoicPoullain@localhost:5432/foal_test_db');
}
}
@Service()
export class User2 extends SequelizeService {
constructor(protected connection: Connection) {
super('users', {
firstName: Sequelize.STRING,
lastName: Sequelize.STRING
}, connection);
}
}
import { preHook, Service } from '@foal/core';
import { EjsTemplateService } from '@foal/ejs';
@Service()
@preHook(ctx => ctx.state.name = 'FoalTS')
export class IndexViewService extends EjsTemplateService {
constructor() {
super('./templates/index.html');
}
}
import { Service } from '@foal/core';
import { Sequelize, SequelizeConnectionService, SequelizeService } from '@foal/sequelize';
export interface User {
firstName: string;
lastName: string;
}
@Service()
export class Connection extends SequelizeConnectionService {
constructor() {
super('postgres://postgres:LoicPoullain@localhost:5432/foal_test_db');
}
}
@Service()
export class User2 extends SequelizeService {
constructor(protected connection: Connection) {
super('users', {
firstName: Sequelize.STRING,
lastName: Sequelize.STRING
}, connection);
}
}
import { EntitySerializer, Service } from '@foal/core';
import { User } from '../entities';
@Service()
export class UserSerializer extends EntitySerializer {
entityClass = User;
}