chore: Typescript database models (#2886)

closes #2798
This commit is contained in:
Tom Moor
2022-01-06 18:24:28 -08:00
committed by GitHub
parent d3cbf250e6
commit b20a341f0c
207 changed files with 5624 additions and 5315 deletions

View File

@@ -1,36 +1,55 @@
import { DataTypes, sequelize } from "../sequelize";
import {
Table,
ForeignKey,
Model,
Column,
PrimaryKey,
IsUUID,
CreatedAt,
BelongsTo,
DataType,
Default,
} from "sequelize-typescript";
import User from "./User";
import Fix from "./decorators/Fix";
const Notification = sequelize.define(
"notification",
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
event: {
type: DataTypes.STRING,
},
email: {
type: DataTypes.BOOLEAN,
},
},
{
timestamps: true,
updatedAt: false,
}
);
@Table({
tableName: "notifications",
modelName: "notification",
updatedAt: false,
})
@Fix
class Notification extends Model {
@IsUUID(4)
@PrimaryKey
@Default(DataType.UUIDV4)
@Column(DataType.UUID)
id: string;
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'models' implicitly has an 'any' type.
Notification.associate = (models) => {
Notification.belongsTo(models.User, {
as: "actor",
foreignKey: "actorId",
});
Notification.belongsTo(models.User, {
as: "user",
foreignKey: "userId",
});
};
@CreatedAt
createdAt: Date;
@Column
event: string;
@Column
email: boolean;
// associations
@BelongsTo(() => User, "userId")
user: User;
@ForeignKey(() => User)
@Column(DataType.UUID)
userId: string;
@BelongsTo(() => User, "actorId")
actor: User;
@ForeignKey(() => User)
@Column(DataType.UUID)
actorId: string;
}
export default Notification;