All files / app/models index.ts

100% Statements 25/25
100% Branches 0/0
100% Functions 0/0
100% Lines 25/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 641x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x         1x 1x 1x 1x         1x         1x         1x 1x 1x 1x         1x         1x               1x              
export * from './user';
export * from './group';
export * from './car';
export * from './membership';
export * from './profile-picture';
export * from './invite';
 
import {User} from './user/user';
import {Group} from './group/group';
import {Membership} from './membership/membership';
import {ProfilePic} from './profile-picture/profile-pic';
import {Invite} from './invite/invite';
import {Car} from './car';
 
/*
 * Add n:m association "Membership" between group and user
 */
Group.belongsToMany(User, {through: Membership});
User.belongsToMany(Group, {through: Membership});
Membership.belongsTo(Group, {as: 'Group', foreignKey: 'groupId'});
Membership.belongsTo(User, {as: 'User', foreignKey: 'userId'});
 
/*
 * Add the 1:n association between groups and users
 */
Group.belongsTo(User, {
  as: 'Owner',
  foreignKey: 'ownerId',
});
 
ProfilePic.belongsTo(User);
 
/*
 * Create the n:m association "Invite" between User and Group
 */
Group.belongsToMany(User, {through: Invite});
User.belongsToMany(Group, {through: Invite});
Invite.belongsTo(Group, {as: 'Group', foreignKey: 'groupId'});
Invite.belongsTo(User, {as: 'User', foreignKey: 'userId'});
 
/**
 * Add the invitedBy association between Invite and User
 */
Invite.belongsTo(User, {as: 'InviteSender', foreignKey: 'invitedBy'});
 
/**
 * Make associations for cars.
 */
Car.belongsTo(
    Group,
    {
      as: 'Group',
      foreignKey: 'groupId',
      onDelete: 'CASCADE',
    },
);
Car.belongsTo(
    User,
    {
      as: 'Driver',
      foreignKey: 'driverId',
    },
);