Skip to content

Commit

Permalink
cleanup: models
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamPalriwala committed Feb 17, 2022
1 parent 19edb5e commit 6a19362
Show file tree
Hide file tree
Showing 18 changed files with 2 additions and 431 deletions.
18 changes: 1 addition & 17 deletions models/basket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import {
InferCreationAttributes,
DataTypes,
CreationOptional,
HasManyCreateAssociationMixin,
HasManyGetAssociationsMixin,
Association,
NonAttribute,
} from "sequelize";
import { sequelize } from "./index";
Expand All @@ -28,7 +25,7 @@ class BasketModel extends Model<
declare UserId: number;
declare id: CreationOptional<number>;
declare coupon: CreationOptional<string> | null;
declare Products?: NonAttribute<ProductModel[]>; // Note this is optional since it's only populated when explicitly requested in code
declare Products?: NonAttribute<ProductModel[]>;
}

BasketModel.init(
Expand Down Expand Up @@ -60,16 +57,3 @@ BasketModel.belongsToMany(ProductModel, {
});

export default BasketModel;

// export = (sequelize, { STRING }) => {
// const Basket = sequelize.define('Basket', {
// coupon: STRING
// })

// Basket.associate = ({ User, Product, BasketItem }) => {
// Basket.belongsTo(User, { constraints: true, foreignKeyConstraint: true })
// Basket.belongsToMany(Product, { through: BasketItem, foreignKey: { name: 'BasketId', noUpdate: true } })
// }

// return Basket
// }
14 changes: 0 additions & 14 deletions models/basketitem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
InferCreationAttributes,
DataTypes,
CreationOptional,
NonAttribute,
} from "sequelize";
import { sequelize } from "./index";

Expand Down Expand Up @@ -41,16 +40,3 @@ BasketItemModel.init(
);

export default BasketItemModel;

// export = (sequelize, { INTEGER }) => {
// const BasketItem = sequelize.define("BasketItem", {
// id: {
// type: INTEGER,
// primaryKey: true,
// autoIncrement: true,
// allowNull: false,
// },
// quantity: INTEGER,
// });
// return BasketItem;
// };
10 changes: 0 additions & 10 deletions models/captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
InferAttributes,
InferCreationAttributes,
DataTypes,
CreationOptional,
} from "sequelize";
import { sequelize } from "./index";

Expand Down Expand Up @@ -38,12 +37,3 @@ CaptchaModel.init(
);

export default CaptchaModel;

// export = (sequelize, { INTEGER, STRING }) => {
// const Captcha = sequelize.define("Captcha", {
// captchaId: INTEGER,
// captcha: STRING,
// answer: STRING,
// });
// return Captcha;
// };
37 changes: 0 additions & 37 deletions models/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
InferCreationAttributes,
DataTypes,
CreationOptional,
NonAttribute,
} from "sequelize";
import { sequelize } from "./index";
import UserModel from "./user";
Expand Down Expand Up @@ -72,39 +71,3 @@ CardModel.belongsTo(UserModel, {
});

export default CardModel;

// export = (sequelize, { STRING, INTEGER }) => {
// const Card = sequelize.define("Card", {
// fullName: STRING,
// cardNum: {
// type: INTEGER,
// validate: {
// isInt: true,
// min: 1000000000000000,
// max: 9999999999999998,
// },
// },
// expMonth: {
// type: INTEGER,
// validate: {
// isInt: true,
// min: 1,
// max: 12,
// },
// },
// expYear: {
// type: INTEGER,
// validate: {
// isInt: true,
// min: 2080,
// max: 2099,
// },
// },
// });

// Card.associate = ({ User }) => {
// Card.belongsTo(User, { constraints: true, foreignKeyConstraint: true });
// };

// return Card;
// };
19 changes: 0 additions & 19 deletions models/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,3 @@ ChallengeModel.init(
);

export default ChallengeModel;

// export = (sequelize, { STRING, INTEGER, BOOLEAN, NUMBER }) => {
// const Challenge = sequelize.define("Challenge", {
// key: STRING,
// name: STRING,
// category: STRING,
// tags: STRING,
// description: STRING,
// difficulty: INTEGER,
// hint: STRING,
// hintUrl: STRING,
// mitigationUrl: STRING,
// solved: BOOLEAN,
// disabledEnv: STRING,
// tutorialOrder: NUMBER,
// codingChallengeStatus: NUMBER,
// });
// return Challenge;
// };
17 changes: 0 additions & 17 deletions models/complaint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
InferCreationAttributes,
DataTypes,
CreationOptional,
NonAttribute,
} from "sequelize";
import { sequelize } from "./index";
import UserModel from "./user";
Expand Down Expand Up @@ -49,19 +48,3 @@ ComplaintModel.belongsTo(UserModel, {
});

export default ComplaintModel;

// export = (sequelize, { STRING }) => {
// const Complaint = sequelize.define("Complaint", {
// message: STRING,
// file: STRING,
// });

// Complaint.associate = ({ User }) => {
// Complaint.belongsTo(User, {
// constraints: true,
// foreignKeyConstraint: true,
// });
// };

// return Complaint;
// };
12 changes: 0 additions & 12 deletions models/delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,3 @@ DeliveryModel.init(
);

export default DeliveryModel;

// export = (sequelize, { FLOAT, STRING }) => {
// const Delivery = sequelize.define("Delivery", {
// name: STRING,
// price: FLOAT,
// deluxePrice: FLOAT,
// eta: FLOAT,
// icon: STRING,
// });

// return Delivery;
// };
42 changes: 0 additions & 42 deletions models/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
InferCreationAttributes,
DataTypes,
CreationOptional,
NonAttribute,
} from "sequelize";
import { sequelize } from "./index";
import UserModel from "./user";
Expand Down Expand Up @@ -74,44 +73,3 @@ FeedbackModel.init(
FeedbackModel.belongsTo(UserModel); // no FK constraint to allow anonymous feedback posts

export default FeedbackModel;
// module.exports = (sequelize, { STRING, INTEGER }) => {
// const Feedback = sequelize.define("Feedback", {
// comment: {
// type: STRING,
// set(comment) {
// let sanitizedComment;
// if (!utils.disableOnContainerEnv()) {
// sanitizedComment = security.sanitizeHtml(comment);
// utils.solveIf(
// challenges.persistedXssFeedbackChallenge,
// () => {
// return utils.contains(
// sanitizedComment,
// '<iframe src="javascript:alert(`xss`)">'
// );
// }
// );
// } else {
// sanitizedComment = security.sanitizeSecure(comment);
// }
// this.setDataValue("comment", sanitizedComment);
// },
// },
// rating: {
// type: INTEGER,
// allowNull: false,
// set(rating) {
// this.setDataValue("rating", rating);
// utils.solveIf(challenges.zeroStarsChallenge, () => {
// return rating === 0;
// });
// },
// },
// });

// Feedback.associate = ({ User }) => {
// Feedback.belongsTo(User); // no FK constraint to allow anonymous feedback posts
// };

// return Feedback;
// };
14 changes: 0 additions & 14 deletions models/imageCaptcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,3 @@ ImageCaptchaModel.init(
ImageCaptchaModel.belongsTo(UserModel);

export default ImageCaptchaModel;

// export = (sequelize, { INTEGER, STRING }) => {
// const ImageCaptcha = sequelize.define("ImageCaptcha", {
// image: STRING,
// answer: STRING,
// UserId: { type: INTEGER },
// });

// ImageCaptcha.associate = ({ User }) => {
// ImageCaptcha.belongsTo(User);
// };

// return ImageCaptcha;
// };
16 changes: 0 additions & 16 deletions models/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
InferCreationAttributes,
DataTypes,
CreationOptional,
NonAttribute,
} from "sequelize";
import { sequelize } from "./index";
import UserModel from "./user";
Expand Down Expand Up @@ -49,18 +48,3 @@ MemoryModel.belongsTo(UserModel, {
});

export default MemoryModel;
// export = (sequelize, { STRING, INTEGER }) => {
// const Memory = sequelize.define("Memory", {
// caption: STRING,
// imagePath: STRING,
// });

// Memory.associate = ({ User }) => {
// Memory.belongsTo(User, {
// constraints: true,
// foreignKeyConstraint: true,
// });
// };

// return Memory;
// };
16 changes: 0 additions & 16 deletions models/privacyRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,3 @@ PrivacyRequestModel.belongsTo(UserModel, {
});

export default PrivacyRequestModel;

// export = (sequelize, { INTEGER, BOOLEAN }) => {
// const PrivacyRequest = sequelize.define("PrivacyRequest", {
// UserId: { type: INTEGER },
// deletionRequested: { type: BOOLEAN, defaultValue: false },
// });

// PrivacyRequest.associate = ({ User }) => {
// PrivacyRequest.belongsTo(User, {
// constraints: true,
// foreignKeyConstraint: true,
// });
// };

// return PrivacyRequest;
// };
41 changes: 1 addition & 40 deletions models/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
InferCreationAttributes,
DataTypes,
CreationOptional,
HasManyCreateAssociationMixin,
NonAttribute,
} from "sequelize";
import { sequelize } from "./index";
Expand All @@ -30,7 +29,7 @@ class ProductModel extends Model<
declare price: number;
declare deluxePrice: number;
declare image: string;
declare BasketItem?: NonAttribute<BasketItemModel>; // Note this is optional since it's only populated when explicitly requested in code
declare BasketItem?: CreationOptional<BasketItemModel>; // Note this is optional since it's only populated when explicitly requested in code

}

Expand Down Expand Up @@ -78,41 +77,3 @@ ProductModel.belongsToMany(BasketModel, {
});

export default ProductModel;

// module.exports = (sequelize, { STRING, DECIMAL }) => {
// const Product = sequelize.define(
// "Product",
// {
// name: STRING,
// description: {
// type: STRING,
// set(description) {
// if (!utils.disableOnContainerEnv()) {
// utils.solveIf(challenges.restfulXssChallenge, () => {
// return utils.contains(
// description,
// '<iframe src="javascript:alert(`xss`)">'
// );
// });
// } else {
// description = security.sanitizeSecure(description);
// }
// this.setDataValue("description", description);
// },
// },
// price: DECIMAL,
// deluxePrice: DECIMAL,
// image: STRING,
// },
// { paranoid: true }
// );

// Product.associate = ({ Basket, BasketItem }) => {
// Product.belongsToMany(Basket, {
// through: BasketItem,
// foreignKey: { name: "ProductId", noUpdate: true },
// });
// };

// return Product;
// };
Loading

0 comments on commit 6a19362

Please sign in to comment.