Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoerlitz committed Mar 10, 2024
2 parents 7e9b2f1 + e06b3ad commit 3863638
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
const { DataType } = require("sequelize-typescript");
import { DataType } from "sequelize-typescript";
import { QueryInterface, Sequelize } from "sequelize";
import { TRAINING_STATIONS_ATTRIBUTES, TRAINING_STATIONS_TABLE_NAME } from "./20221115171252-create-training-stations-table";

const UserSolosModelAttributes = {
export const USER_SOLOS_TABLE_NAME = "user_solos";

export const USER_SOLOS_ATTRIBUTES = {
id: {
type: DataType.INTEGER,
primaryKey: true,
autoIncrement: true,
},
vateud_solo_id: {
type: DataType.INTEGER,
allowNull: true,
defaultValue: null,
},
user_id: {
unique: true,
type: DataType.INTEGER,
Expand Down Expand Up @@ -49,12 +58,12 @@ const UserSolosModelAttributes = {
updatedAt: DataType.DATE,
};

module.exports = {
async up(queryInterface) {
await queryInterface.createTable("user_solos", UserSolosModelAttributes);
export default {
async up(queryInterface: QueryInterface, sequelize: Sequelize) {
await queryInterface.createTable(USER_SOLOS_TABLE_NAME, USER_SOLOS_ATTRIBUTES);
},

async down(queryInterface) {
await queryInterface.dropTable("user_solos");
async down(queryInterface: QueryInterface, sequelize: Sequelize) {
await queryInterface.dropTable(TRAINING_STATIONS_TABLE_NAME);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const TRAINING_STATIONS_ATTRIBUTES = {
updatedAt: DataType.DATE,
};

module.exports = {
export default {
async up(queryInterface: QueryInterface, sequelize: Sequelize) {
await queryInterface.createTable(TRAINING_STATIONS_TABLE_NAME, TRAINING_STATIONS_ATTRIBUTES);
},
Expand Down
28 changes: 0 additions & 28 deletions src/core/tasks/UpdateTrainingStationsTask.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
import { EndorsementGroupsBelongsToUsers } from "../../models/through/EndorsementGroupsBelongsToUsers";
import dayjs from "dayjs";
import JobLibrary, { JobTypeEnum } from "../../libraries/JobLibrary";
import { EndorsementGroup } from "../../models/EndorsementGroup";
import { EndorsementGroupBelongsToStations } from "../../models/through/EndorsementGroupBelongsToStations";

async function handle() {
console.log("Handle...");

const endorsementGroupsBelongsToUsers = await EndorsementGroupsBelongsToUsers.findAll({
include: [EndorsementGroupsBelongsToUsers.associations.userSolo, EndorsementGroupsBelongsToUsers.associations.user],
});

console.log(endorsementGroupsBelongsToUsers.length);

for (const solo of endorsementGroupsBelongsToUsers) {
if (solo.user == null || solo.userSolo == null) continue;

if (dayjs.utc(solo.userSolo?.current_solo_end).isBefore(dayjs.utc())) {
console.log(`Solo ID ${solo.solo_id} [user_id = ${solo.user_id}] has expired. Removing Endorsement Group...`);

await solo.destroy();
} else {
console.log(
`Solo ID ${solo.solo_id} [user_id = ${solo.user_id}] is expiring on ${dayjs.utc(solo.userSolo.current_solo_end)} (${Math.abs(
dayjs.utc(solo.userSolo.current_solo_end).diff(dayjs.utc(), "day")
)} Day(s) remaining).`
);
}
}
}

export default {
Expand Down
58 changes: 6 additions & 52 deletions src/models/UserSolo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Model, InferAttributes, CreationOptional, InferCreationAttributes, Fore
import { User } from "./User";
import { DataType } from "sequelize-typescript";
import { sequelize } from "../core/Sequelize";
import { USER_SOLOS_ATTRIBUTES, USER_SOLOS_TABLE_NAME } from "../../db/migrations/20221115171243-create-user-solos";

export class UserSolo extends Model<InferAttributes<UserSolo>, InferCreationAttributes<UserSolo>> {
//
Expand All @@ -15,6 +16,7 @@ export class UserSolo extends Model<InferAttributes<UserSolo>, InferCreationAttr
// Optional Attributes
//
declare id: CreationOptional<number>;
declare vateud_solo_id: CreationOptional<number> | null;
declare created_by: CreationOptional<ForeignKey<User["id"]>>;
declare current_solo_start: CreationOptional<Date> | null;
declare current_solo_end: CreationOptional<Date> | null;
Expand All @@ -33,55 +35,7 @@ export class UserSolo extends Model<InferAttributes<UserSolo>, InferCreationAttr
};
}

UserSolo.init(
{
id: {
type: DataType.INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_id: {
unique: true,
type: DataType.INTEGER,
allowNull: false,
references: {
model: "users",
key: "id",
},
onUpdate: "cascade",
onDelete: "cascade",
},
created_by: {
type: DataType.INTEGER,
allowNull: true,
references: {
model: "users",
key: "id",
},
onUpdate: "cascade",
onDelete: "set null",
},
solo_used: {
type: DataType.INTEGER,
allowNull: false,
},
extension_count: {
type: DataType.INTEGER,
allowNull: false,
},
current_solo_start: {
type: DataType.DATE,
allowNull: true,
},
current_solo_end: {
type: DataType.DATE,
allowNull: true,
},
createdAt: DataType.DATE,
updatedAt: DataType.DATE,
},
{
tableName: "user_solos",
sequelize: sequelize,
}
);
UserSolo.init(USER_SOLOS_ATTRIBUTES, {
tableName: USER_SOLOS_TABLE_NAME,
sequelize: sequelize,
});

0 comments on commit 3863638

Please sign in to comment.