Conversation
Updated migration, model and seeders
Authentication Api integration Done.
added admins
| @@ -1 +1,25 @@ | |||
| node_modules/ No newline at end of file | |||
| (async () => { | ||
| try { | ||
| await db.sequelize.authenticate(); | ||
| console.log("Database connection has been established successfully."); | ||
| } catch (error) { | ||
| console.error("Unable to connect to the database:", error); | ||
| } | ||
| })(); |
There was a problem hiding this comment.
this should be handled in the db index file, not here
| // type: DataTypes.INTEGER, | ||
| // references: { | ||
| // model: "users", | ||
| // key: "id", | ||
| // }, | ||
| // }, | ||
| // event_id: { | ||
| // type: DataTypes.INTEGER, | ||
| // references: { | ||
| // model: "events", | ||
| // key: "id", | ||
| // }, | ||
| // }, |
There was a problem hiding this comment.
by now you should know that this is not clean code for a review :)
| this.hasMany(models.event); | ||
| } | ||
| } | ||
| Admin.init( |
| this.hasMany(models.event); | ||
| } | ||
| } | ||
| Category.init( |
There was a problem hiding this comment.
what's the pk? Please make sure your models are always a representation of your DB table
| } | ||
| } | ||
|
|
||
| async getAllStatuses(req, res) { |
There was a problem hiding this comment.
Same here. Why does status logic sit in categories?
| { model: this.adminModel, as: "admin" }, | ||
| { model: this.venueModel, as: "venue" }, | ||
| { model: this.languageModel, as: "language" }, | ||
| { model: this.categoryModel, as: "category" }, |
| output = await this.model.findAll(queryOptions); | ||
| } else { | ||
| output = await this.model.findAll(queryOptions); |
There was a problem hiding this comment.
Output will always be the result of the same query. So why not just use a constant for output, without the if/else statement?
...
if (keyword !== "all") {
queryOptions.where = {
title: { [Op.iLike]: `%${keyword}%` },
};
}
const output = await this.model.findAll(queryOptions);
| image_link, | ||
| } = req.body; | ||
| try { | ||
| const newEvent = await this.model.create({ |
There was a problem hiding this comment.
since you do not run any validation (which you should), why not just do this.model.create(req.body) ?
| async insertOne(req, res) { | ||
| const { postal_code, address, lat, lng, country } = req.body; | ||
| try { | ||
| let venue = await this.model.findOne({ |
There was a problem hiding this comment.
We can use this.model.findOrCreate for this function. Though it seems a bit wrong to do that as well. Your function is trying to insert one, not to find one. So you should try to decide what this should do, including your route.
No description provided.