Skip to content

Commit

Permalink
[feature] learn and earn user lesson (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Pedro da Silva authored Nov 15, 2023
1 parent 4ff2b39 commit 86c44ce
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ module.exports = {
allowNull: false,
defaultValue: 0,
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
},
});
},
down: (queryInterface) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
if (process.env.NODE_ENV === 'test') {
return;
}

await queryInterface.addColumn('learn_and_earn_user_lesson', 'createdAt', {
type: Sequelize.DATE,
allowNull: true
});

await queryInterface.sequelize.query(`
UPDATE learn_and_earn_user_lesson
SET "createdAt" = COALESCE("completionDate", CURRENT_DATE);
`);

await queryInterface.changeColumn('learn_and_earn_user_lesson', 'createdAt', {
type: Sequelize.DATE,
allowNull: false
});
},
async down(queryInterface, Sequelize) {
//
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class LearnAndEarnUserLessonModel extends Model<LearnAndEarnUserLesson, L
public completionDate!: Date;
public attempts!: number;
public points!: number;

public readonly createdAt!: Date;
}

export function initializeLearnAndEarnUserLesson(sequelize: Sequelize): typeof LearnAndEarnUserLessonModel {
Expand Down Expand Up @@ -62,12 +64,16 @@ export function initializeLearnAndEarnUserLesson(sequelize: Sequelize): typeof L
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
createdAt: {
type: DataTypes.DATE,
allowNull: false
}
},
{
tableName: 'learn_and_earn_user_lesson',
modelName: 'learnAndEarnUserLesson',
timestamps: false,
updatedAt: false,
sequelize
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface LearnAndEarnUserLesson {
completionDate: Date;
attempts: number;
points: number;
createdAt: Date;
}

export interface LearnAndEarnUserLessonCreation {
Expand Down

0 comments on commit 86c44ce

Please sign in to comment.