Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

member verification table #56

Merged
merged 5 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('membership_verification_codes', {
id: {
type: Sequelize.UUID,
primaryKey: true,
allowNull: false,
},
membershipId: {
type: Sequelize.UUID,
allowNull: false,
references: {
model: 'memberships',
key: 'id',
},
},
code: {
type: Sequelize.STRING,
allowNull: false,
},
expiration: {
type: Sequelize.DATE,
allowNull: false,
},
});
},

async down(queryInterface) {
await queryInterface.dropTable('photos');
},
};
4 changes: 3 additions & 1 deletion src/db/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import User from './user';
import Resource from './resource';
import VerificationCode from './verification_code';
import Team from './team';
import Team from './team';
import Membership from './membership';
import Herd from './herd';
import CowCensus from './cow_census';
import MemberVerificationCode from './membership_verification_code';

export {
User,
Expand All @@ -14,4 +15,5 @@ export {
Membership,
Herd,
CowCensus,
MemberVerificationCode,
};
55 changes: 55 additions & 0 deletions src/db/models/membership_verification_code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
AllowNull,
Column,
Default,
ForeignKey,
Model,
PrimaryKey,
Table,
Unique,
} from 'sequelize-typescript';
import { DataTypes } from 'sequelize';
import Membership from './membership';

export interface IMemberVerificationCode {
id: string;
/**
* Foreign key pointing to the user who created the code
*/
membershipId: string;
/**
* The verification code generated for sharing
*/
code: string;

/**
* The expiration date of the verification code
*/
expiration: Date;
}

@Table({
tableName: 'membership_verification_codes',
})
class MemberVerificationCode extends Model<IMemberVerificationCode> implements IMemberVerificationCode {
@PrimaryKey
@Default(DataTypes.UUIDV4)
@Column({ type: DataTypes.UUID })
id: string;

@Unique
@ForeignKey(() => Membership)
@AllowNull(false)
@Column({ type: DataTypes.UUID })
membershipId: string;

@AllowNull(false)
@Column(DataTypes.STRING)
code: string;

@AllowNull(false)
@Column(DataTypes.DATE)
expiration: Date;
}

export default MemberVerificationCode;