alpha
This commit is contained in:
69
backend/models/AlphaInvitation.js
Normal file
69
backend/models/AlphaInvitation.js
Normal 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;
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user