How to use @foal/typeorm - 10 common examples

To help you get started, we’ve selected a few @foal/typeorm 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 / acceptance-tests / src / auth.typeorm.spec.ts View on Github external
await Promise.all([
      request(app).get('/foo').set('Cookie', cookie).expect(200),
      request(app).get('/bar').set('Cookie', cookie).expect(403),
    ]);

    /* Add the admin group and permission */

    await createConnection({
      database: 'e2e_db.sqlite',
      entities: [ User, Permission, Group ],
      name: 'perm-connection',
      type: 'sqlite',
    });

    const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
    if (!user2) {
      throw new Error('John was not found in the database.');
    }

    const perm = new Permission();
    perm.codeName = 'admin';
    perm.name = 'Admin permission';
    await getRepository(Permission, 'perm-connection').save(perm);

    const group = new Group();
    group.name = 'Administrators';
    group.codeName = 'administrators';
    group.permissions = [ perm ];
    await getRepository(Group, 'perm-connection').save(group);

    user2.groups = [ group ];
github FoalTS / foal / packages / acceptance-tests / src / auth.spec.ts View on Github external
throw new Error('John was not found in the database.');
    }

    const perm = new Permission();
    perm.codeName = 'admin';
    perm.name = 'Admin permission';
    await getRepository(Permission, 'perm-connection').save(perm);

    const group = new Group();
    group.name = 'Administrators';
    group.codeName = 'administrators';
    group.permissions = [ perm ];
    await getRepository(Group, 'perm-connection').save(group);

    user2.groups = [ group ];
    await getRepository(User, 'perm-connection').save(user2);

    await getConnection('perm-connection').close();

    /* Access the route that requires a specific permission */

    await request(app).get('/bar').set('Cookie', cookie).expect(200);

    /* Log out */

    await request(app).get('/logout').set('Cookie', cookie).expect(204);

    /* Try to access routes that require authentication and a specific permission */

    await Promise.all([
      request(app).get('/foo').expect(401),
      request(app).get('/bar').expect(401),
github FoalTS / foal / packages / acceptance-tests / src / auth.spec.ts View on Github external
const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
    if (!user2) {
      throw new Error('John was not found in the database.');
    }

    const perm = new Permission();
    perm.codeName = 'admin';
    perm.name = 'Admin permission';
    await getRepository(Permission, 'perm-connection').save(perm);

    const group = new Group();
    group.name = 'Administrators';
    group.codeName = 'administrators';
    group.permissions = [ perm ];
    await getRepository(Group, 'perm-connection').save(group);

    user2.groups = [ group ];
    await getRepository(User, 'perm-connection').save(user2);

    await getConnection('perm-connection').close();

    /* Access the route that requires a specific permission */

    await request(app).get('/bar').set('Cookie', cookie).expect(200);

    /* Log out */

    await request(app).get('/logout').set('Cookie', cookie).expect(204);

    /* Try to access routes that require authentication and a specific permission */
github FoalTS / foal / packages / acceptance-tests / src / auth.spec.ts View on Github external
const perm = new Permission();
    perm.codeName = 'admin';
    perm.name = 'Admin permission';
    await getRepository(Permission, 'perm-connection').save(perm);

    const group = new Group();
    group.name = 'Administrators';
    group.codeName = 'administrators';
    group.permissions = [ perm ];
    await getRepository(Group, 'perm-connection').save(group);

    user2.groups = [ group ];
    await getRepository(User, 'perm-connection').save(user2);

    await getConnection('perm-connection').close();

    /* Access the route that requires a specific permission */

    await request(app).get('/bar').set('Cookie', cookie).expect(200);

    /* Log out */

    await request(app).get('/logout').set('Cookie', cookie).expect(204);

    /* Try to access routes that require authentication and a specific permission */

    await Promise.all([
      request(app).get('/foo').expect(401),
      request(app).get('/bar').expect(401),
    ]);
github FoalTS / foal / packages / acceptance-tests / src / auth.typeorm.spec.ts View on Github external
await createConnection({
      database: 'e2e_db.sqlite',
      dropSchema: true,
      entities: [ User, Permission, Group ],
      name: 'create-connection',
      synchronize: true,
      type: 'sqlite',
    });

    const user = new User();
    user.email = 'john@foalts.org';
    user.password = await hashPassword('password');
    await getRepository(User, 'create-connection').save(user);

    await getConnection('create-connection').close();

    /* Try to access routes that require authentication and a specific permission */

    await Promise.all([
      request(app).get('/foo').expect(401),
      request(app).get('/bar').expect(401),
    ]);

    /* Try to login with a wrong email */

    await request(app)
      .post('/login')
      .send({ email: 'mary@foalts.org', password: 'password' })
      .expect(401);

    /* Try to login with a wrong password */
github FoalTS / foal / packages / acceptance-tests / src / auth.typeorm.spec.ts View on Github external
entities: [ User, Permission, Group ],
      name: 'perm-connection',
      type: 'sqlite',
    });

    const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
    if (!user2) {
      throw new Error('John was not found in the database.');
    }

    const perm = new Permission();
    perm.codeName = 'admin';
    perm.name = 'Admin permission';
    await getRepository(Permission, 'perm-connection').save(perm);

    const group = new Group();
    group.name = 'Administrators';
    group.codeName = 'administrators';
    group.permissions = [ perm ];
    await getRepository(Group, 'perm-connection').save(group);

    user2.groups = [ group ];
    await getRepository(User, 'perm-connection').save(user2);

    await getConnection('perm-connection').close();

    /* Access the route that requires a specific permission */

    await request(app).get('/bar').set('Cookie', cookie).expect(200);

    /* Log out */
github FoalTS / foal / packages / acceptance-tests / src / auth.spec.ts View on Github external
entities: [ User, Permission, Group ],
      name: 'perm-connection',
      type: 'sqlite',
    });

    const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
    if (!user2) {
      throw new Error('John was not found in the database.');
    }

    const perm = new Permission();
    perm.codeName = 'admin';
    perm.name = 'Admin permission';
    await getRepository(Permission, 'perm-connection').save(perm);

    const group = new Group();
    group.name = 'Administrators';
    group.codeName = 'administrators';
    group.permissions = [ perm ];
    await getRepository(Group, 'perm-connection').save(group);

    user2.groups = [ group ];
    await getRepository(User, 'perm-connection').save(user2);

    await getConnection('perm-connection').close();

    /* Access the route that requires a specific permission */

    await request(app).get('/bar').set('Cookie', cookie).expect(200);

    /* Log out */
github FoalTS / foal / packages / acceptance-tests / src / auth.typeorm.spec.ts View on Github external
/* Add the admin group and permission */

    await createConnection({
      database: 'e2e_db.sqlite',
      entities: [ User, Permission, Group ],
      name: 'perm-connection',
      type: 'sqlite',
    });

    const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
    if (!user2) {
      throw new Error('John was not found in the database.');
    }

    const perm = new Permission();
    perm.codeName = 'admin';
    perm.name = 'Admin permission';
    await getRepository(Permission, 'perm-connection').save(perm);

    const group = new Group();
    group.name = 'Administrators';
    group.codeName = 'administrators';
    group.permissions = [ perm ];
    await getRepository(Group, 'perm-connection').save(group);

    user2.groups = [ group ];
    await getRepository(User, 'perm-connection').save(user2);

    await getConnection('perm-connection').close();

    /* Access the route that requires a specific permission */
github FoalTS / foal / packages / acceptance-tests / src / auth.spec.ts View on Github external
/* Add the admin group and permission */

    await createConnection({
      database: 'e2e_db.sqlite',
      entities: [ User, Permission, Group ],
      name: 'perm-connection',
      type: 'sqlite',
    });

    const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
    if (!user2) {
      throw new Error('John was not found in the database.');
    }

    const perm = new Permission();
    perm.codeName = 'admin';
    perm.name = 'Admin permission';
    await getRepository(Permission, 'perm-connection').save(perm);

    const group = new Group();
    group.name = 'Administrators';
    group.codeName = 'administrators';
    group.permissions = [ perm ];
    await getRepository(Group, 'perm-connection').save(group);

    user2.groups = [ group ];
    await getRepository(User, 'perm-connection').save(user2);

    await getConnection('perm-connection').close();

    /* Access the route that requires a specific permission */
github FoalTS / foal / packages / cli / src / generate / specs / service / test-foo-bar.service.entity-resource-collection.ts View on Github external
properties: {
    // To complete
  },
  required: [ /* To complete */ ],
  type: 'object',
};

export class TestFooBarCollection extends EntityResourceCollection {
  // tslint:disable-next-line:whitespace
  entityClass = TestFooBar;
  allowedOperations: EntityResourceCollection['allowedOperations'] = [
    'create', 'findById', 'find', 'modifyById', 'updateById', 'deleteById'
  ];

  middlewares = [
    middleware('create|modifyById|updateById', ({ data }) => validate(schema, data))
  ];
}