How to use the @foal/core.Service function in @foal/core

To help you get started, we’ve selected a few @foal/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FoalTS / foal / packages / cli / src / generate / specs / service / test-foo-bar.service.graphql-resolver.ts View on Github external
import { GraphQLResolver, Service } from '@foal/core';

@Service()
export class TestFooBarResolver extends GraphQLResolver {

}
github FoalTS / foal / packages / examples / src / app / services / user.controller.ts View on Github external
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();
  }
github FoalTS / foal / packages / common / src / controller-factories / view.controller-factory.spec.ts View on Github external
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');
github FoalTS / foal / packages / core / e2e / src / app / module-1 / toto.controller.ts View on Github external
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) {

  }
github FoalTS / foal / packages / examples / src / app / authentication / login-view.service.ts View on Github external
import { Service } from '@foal/core';
import { EjsTemplateService } from '@foal/ejs';

@Service()
export class LoginViewService extends EjsTemplateService {
  constructor() {
    super('./templates/login.html');
  }
}
github FoalTS / foal / packages / examples / src / app / shared / connection.service.ts View on Github external
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);
  }
}
github FoalTS / foal / packages / examples / src / app / my-module / services / user2.controller.ts View on Github external
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);
  }
}
github FoalTS / foal / packages / examples / src / app / services / index-view.service.ts View on Github external
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');
  }
}
github FoalTS / foal / packages / examples / src / app / my-module / services / user2.controller.ts View on Github external
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);
  }
}
github FoalTS / foal / packages / examples / src / app / services / user-serializer.service.ts View on Github external
import { EntitySerializer, Service } from '@foal/core';

import { User } from '../entities';

@Service()
export class UserSerializer extends EntitySerializer {
  entityClass = User;
}