Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: New rating framework #42

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint:fix": "eslint . --fix",
"build": "babel src --out-dir dist --source-maps inline --copy-files",
"start": "babel-node dist/app.js",
"test": "cross-env NODE_ENV=test npm run db:migrate && npm run db:reset && cross-env NODE_ENV=test PORT=4300 mocha --require @babel/register --exit 'src/tests/**/*.test.js'",
"test": "cross-env NODE_ENV=test npm run db:migrate && cross-env NODE_ENV=test npm run db:reset && cross-env NODE_ENV=test PORT=4300 mocha --require @babel/register --exit 'src/tests/**/*.test.js'",
"test:coverage": " nyc mocha --coverage --recursive --require @babel/polyfill --require @babel/register */tests/*.js --timeout 500000000 --exit",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"db:migrate": "sequelize db:migrate",
Expand Down Expand Up @@ -51,7 +51,8 @@
"pg-hstore": "^2.3.4",
"sequelize": "^6.29.0",
"source-map": "^0.7.4",
"swagger-ui-express": "^4.6.1"
"swagger-ui-express": "^4.6.1",
"valibot": "^0.30.0"
},
"devDependencies": {
"@babel/core": "^7.20.12",
Expand Down
10 changes: 8 additions & 2 deletions src/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import ProjectModel from "./models/project";
import UserProject from "./models/userProject";
import NotificationModel from "./models/notification";
import BlacklistedTokenModel from "./models/blacklistedToken";
import ReviewModel from "./models/review";
import OverallReviewModel from "./models/overallReview";
import ReviewCycleModel from "./models/reviewCycle";
import reviewerModel from "./models/reviewer";
import RatingCategoryModel from "./models/ratingCategory";
import RatingFieldModel from "./models/ratingField";
import FieldReviewModel from "./models/fieldReview";

const DB = {
sequelize, // connection instance (RAW queries)
Expand All @@ -15,9 +18,12 @@ const DB = {
UserProject: UserProject(sequelize),
Notification: NotificationModel(sequelize),
BlacklistedToken: BlacklistedTokenModel(sequelize),
Review: ReviewModel(sequelize),
OverallReview: OverallReviewModel(sequelize),
ReviewCycle: ReviewCycleModel(sequelize),
Reviewer: reviewerModel(sequelize),
RatingCategory: RatingCategoryModel(sequelize),
RatingField: RatingFieldModel(sequelize),
FieldReview: FieldReviewModel(sequelize),
};

export default DB;
32 changes: 32 additions & 0 deletions src/database/migrations/20240501212252-rating-categories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("tbl_rating_categories", {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true,
unique: true,
allowNull: false,
},
name: {
type: Sequelize.STRING,
unique: true,
allowNull: false,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
},
});
},

down: async (queryInterface) => {
await queryInterface.dropTable("tbl_rating_categories");
},
};
39 changes: 39 additions & 0 deletions src/database/migrations/20240501213041-RatingField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"use strict";

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("tbl_rating_fields", {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true,
allowNull: false,
unique: true,
},
name: {
type: Sequelize.STRING,
unique: true,
allowNull: false,
},
categoryId: {
type: Sequelize.UUID,
references: {
model: "tbl_rating_categories",
key: "id",
},
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
},
});
},

down: async (queryInterface) => {
await queryInterface.dropTable("tbl_rating_fields");
},
};
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
/* eslint-disable no-unused-vars */
"use strict";

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("tbl_reviews", {
await queryInterface.createTable("tbl_overall_reviews", {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true,
allowNull: false,
unique: true,
},
ratingz: {
type: Sequelize.INTEGER,
},
description: {
comment: {
type: Sequelize.TEXT,
},
reviewerId: {
type: Sequelize.UUID,
allowNull: false,
references: {
model: "tbl_users",
key: "id",
},
},
revieweeId: {
type: Sequelize.UUID,
allowNull: false,
references: {
model: "tbl_users",
key: "id",
},
},
reviewCycleId: {
type: Sequelize.UUID,
allowNull: false,
references: {
model: "tbl_review_cycles",
key: "id",
},
},
type: {
type: Sequelize.STRING,
Expand All @@ -51,7 +48,7 @@ module.exports = {
});
},

down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable("tbl_reviews");
down: async (queryInterface) => {
await queryInterface.dropTable("tbl_overall_reviews");
},
};
45 changes: 45 additions & 0 deletions src/database/migrations/20240503210456-field-reviews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("tbl_field_reviews", {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true,
unique: true,
allowNull: false,
},
ratingFieldId: {
type: Sequelize.UUID,
references: {
model: "tbl_rating_fields",
key: "id",
},
},
overallReviewId: {
type: Sequelize.UUID,
references: {
model: "tbl_overall_reviews",
key: "id",
},
},
ratings: {
type: Sequelize.INTEGER,
allowNull: false,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
},
});
},

down: async (queryInterface) => {
await queryInterface.dropTable("tbl_field_reviews");
},
};
46 changes: 46 additions & 0 deletions src/database/models/fieldReview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Model, DataTypes } from "sequelize";
import sequelize from "../config/sequelize";

class FieldReview extends Model {}

const FieldReviewModel = () => {
FieldReview.init(
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
unique: true,
allowNull: false,
},
ratingFieldId: {
type: DataTypes.UUID,
references: {
model: "tbl_rating_fields",
key: "id",
},
},
overallReviewId: {
type: DataTypes.UUID,
references: {
model: "tbl_overall_reviews",
key: "id",
},
},
ratings: {
type: DataTypes.INTEGER,
allowNull: false,
},
},
{
sequelize,
modelName: "FieldReview",
tableName: "tbl_field_reviews",
timestamps: true,
}
);

return FieldReview;
};

export default FieldReviewModel;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import { Model, DataTypes } from "sequelize";
import sequelize from "../config/sequelize";

class Review extends Model {}
class OverallReview extends Model {}

const ReviewModel = () => {
Review.init(
const OverallReviewModel = () => {
OverallReview.init(
{
id: {
type: DataTypes.UUID,
Expand All @@ -14,10 +14,7 @@ const ReviewModel = () => {
allowNull: false,
unique: true,
},
ratingz: {
type: DataTypes.INTEGER,
},
description: {
comment: {
type: DataTypes.TEXT,
},
reviewerId: {
Expand All @@ -43,25 +40,17 @@ const ReviewModel = () => {
},
type: {
type: DataTypes.STRING,
// allowNull: false
},
createdAt: {
type: DataTypes.DATE,
defaultValue: new Date(),
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: new Date(),
},
},
{
sequelize,
modelName: "Review",
tableName: "tbl_reviews",
modelName: "OverallReview",
tableName: "tbl_overall_reviews",
timestamps: true,
}
);

return Review;
return OverallReview;
};

export default ReviewModel;
export default OverallReviewModel;
32 changes: 32 additions & 0 deletions src/database/models/ratingCategory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Model, DataTypes } from "sequelize";
import sequelize from "../config/sequelize";

class RatingCategory extends Model {}

const RatingCategoryModel = () => {
RatingCategory.init(
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
unique: true,
allowNull: false,
},
name: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
},
},
{
sequelize,
modelName: "RatingCategory",
tableName: "tbl_rating_categories",
timestamps: true,
}
);
return RatingCategory;
};

export default RatingCategoryModel;
Loading
Loading