This commit is contained in:
jackiettran
2025-10-30 15:38:57 -04:00
parent d1cb857aa7
commit ee3a6fd8e1
13 changed files with 1400 additions and 12 deletions

View File

@@ -0,0 +1,69 @@
const { DataTypes } = require("sequelize");
const sequelize = require("../config/database");
const AlphaInvitation = sequelize.define(
"AlphaInvitation",
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
code: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
validate: {
is: /^ALPHA-[A-Z0-9]{8}$/i,
},
},
email: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
validate: {
isEmail: true,
},
set(value) {
// Normalize email to lowercase
this.setDataValue("email", value.toLowerCase().trim());
},
},
usedBy: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: "Users",
key: "id",
},
},
usedAt: {
type: DataTypes.DATE,
allowNull: true,
},
status: {
type: DataTypes.ENUM("pending", "active", "revoked"),
defaultValue: "pending",
allowNull: false,
},
notes: {
type: DataTypes.TEXT,
allowNull: true,
},
},
{
indexes: [
{
fields: ["code"],
},
{
fields: ["email"],
},
{
fields: ["status"],
},
],
}
);
module.exports = AlphaInvitation;

View File

@@ -7,6 +7,7 @@ const ItemRequest = require("./ItemRequest");
const ItemRequestResponse = require("./ItemRequestResponse");
const UserAddress = require("./UserAddress");
const ConditionCheck = require("./ConditionCheck");
const AlphaInvitation = require("./AlphaInvitation");
User.hasMany(Item, { as: "ownedItems", foreignKey: "ownerId" });
Item.belongsTo(User, { as: "owner", foreignKey: "ownerId" });
@@ -71,6 +72,16 @@ ConditionCheck.belongsTo(User, {
foreignKey: "submittedBy",
});
// AlphaInvitation associations
AlphaInvitation.belongsTo(User, {
as: "user",
foreignKey: "usedBy",
});
User.hasMany(AlphaInvitation, {
as: "alphaInvitations",
foreignKey: "usedBy",
});
module.exports = {
sequelize,
User,
@@ -81,4 +92,5 @@ module.exports = {
ItemRequestResponse,
UserAddress,
ConditionCheck,
AlphaInvitation,
};