From 4dae3adb1eb50e3c4ad36bf45edf1b79254fceea Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Thu, 31 Jul 2025 11:42:45 -0400 Subject: [PATCH 01/17] added user models --- database/user.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/database/user.js b/database/user.js index 755c757..8418144 100644 --- a/database/user.js +++ b/database/user.js @@ -3,14 +3,27 @@ const db = require("./db"); const bcrypt = require("bcrypt"); const User = db.define("user", { - username: { + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true, + }, + + name: { type: DataTypes.STRING, allowNull: false, - unique: true, - validate: { - len: [3, 20], - }, }, + + bio: { + type: DataTypes.TEXT, + allowNull: true + }, + + avatar_url: { + type: DataTypes.ENUM("image", "gif"), + allowNull: true, + }, + email: { type: DataTypes.STRING, allowNull: true, @@ -19,15 +32,23 @@ const User = db.define("user", { isEmail: true, }, }, + auth0Id: { type: DataTypes.STRING, allowNull: true, unique: true, }, - passwordHash: { + + password_hash: { type: DataTypes.STRING, allowNull: true, + comment: "Securely hashed password", }, + + created_at: { + type: DataTypes.DATE, + defaultValue: DataTypes.NOW + } }); // Instance method to check password From fc7abb9bf0d9b73b29bba724db60d0931bb450fb Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Thu, 31 Jul 2025 14:17:33 -0400 Subject: [PATCH 02/17] added echoes model --- database/echoes.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 database/echoes.js diff --git a/database/echoes.js b/database/echoes.js new file mode 100644 index 0000000..1a166ac --- /dev/null +++ b/database/echoes.js @@ -0,0 +1,58 @@ +const { DataTypes } = require("sequelize"); +const db = require("./db"); + +const Echoes = db.define("user", { + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true, + }, + + sender_id: { + type: DataTypes.INTEGER, + allowNull: false + }, + + type: { + type: DataTypes.ENUM("self", "friend", "public"), + allowNull: false, + }, + + text: { + type: DataTypes.STRING, + allowNull: true, + }, + + unlock_datetime: { + type: DataTypes.DATE, + allowNull: false + }, + + is_unlocked: { + type: DataTypes.VIRTUAL, + get() { + const now = new Date(); + return now >= this.unlock_datetime; + } + }, + + is_archived: { + type: DataTypes.BOOLEAN, + defaultValue: false, + allowNull: false, + }, + + show_sender_name: { + type: DataTypes.BOOLEAN, + defaultValue: false, + allowNull: false, + } + +}, { + tableName: 'Echoes', + timestamps: true, + createdAt: 'created_at', + updatedAt: 'updated_at', +}); + +module.exports = Echoes; From 1eb36d2fc7d382729debe37771914d05eebee59e Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Thu, 31 Jul 2025 14:29:03 -0400 Subject: [PATCH 03/17] created multiple users in seed for testing purposes and updated table name in Users model --- database/seed.js | 7 ++++--- database/user.js | 18 +++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/database/seed.js b/database/seed.js index e58b595..d23ee7e 100644 --- a/database/seed.js +++ b/database/seed.js @@ -7,9 +7,10 @@ const seed = async () => { await db.sync({ force: true }); // Drop and recreate tables const users = await User.bulkCreate([ - { username: "admin", passwordHash: User.hashPassword("admin123") }, - { username: "user1", passwordHash: User.hashPassword("user111") }, - { username: "user2", passwordHash: User.hashPassword("user222") }, + { name: "jeramy", password_hash: User.hashPassword("123"), email: "jeramy@gmail.com" }, + { name: "aiyanna", password_hash: User.hashPassword("456"), email: "aiyanna@gmail.com" }, + { name: "emmanuel", password_hash: User.hashPassword("789"), email: "emmanuel@gmail.com" }, + { name: "olivia", password_hash: User.hashPassword("101112"), email: "olivia@gmail.com" }, ]); console.log(`👤 Created ${users.length} users`); diff --git a/database/user.js b/database/user.js index 8418144..665ca55 100644 --- a/database/user.js +++ b/database/user.js @@ -26,7 +26,7 @@ const User = db.define("user", { email: { type: DataTypes.STRING, - allowNull: true, + allowNull: false, unique: true, validate: { isEmail: true, @@ -43,20 +43,20 @@ const User = db.define("user", { type: DataTypes.STRING, allowNull: true, comment: "Securely hashed password", - }, - - created_at: { - type: DataTypes.DATE, - defaultValue: DataTypes.NOW - } + }, +},{ + tableName: 'users', + timestamps: true, + createdAt: 'created_at', + updatedAt: 'updated_at', }); // Instance method to check password User.prototype.checkPassword = function (password) { - if (!this.passwordHash) { + if (!this.password_hash) { return false; // Auth0 users don't have passwords } - return bcrypt.compareSync(password, this.passwordHash); + return bcrypt.compareSync(password, this.password_hash); }; // Class method to hash password From d361c72f4df2c0a808c66adb98c0c2bd0f667193 Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Thu, 31 Jul 2025 14:46:02 -0400 Subject: [PATCH 04/17] issues connecting to database resolved --- .env.example | 3 --- package-lock.json | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index 848ad61..0000000 --- a/.env.example +++ /dev/null @@ -1,3 +0,0 @@ -DATABASE_URL=postgres://hostname:5432/database-name -JWT_SECRET=super-secret-jwt-key -FRONTEND_URL=http://localhost:3000 diff --git a/package-lock.json b/package-lock.json index af0cf82..1b30289 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "capstone-i-backend", + "name": "capstone-1-backend", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "capstone-i-backend", + "name": "capstone-1-backend", "version": "1.0.0", "license": "ISC", "dependencies": { From 7cc241bc225a540c2835f37bf907e01be0fce558 Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Thu, 31 Jul 2025 15:14:09 -0400 Subject: [PATCH 05/17] changed name attribute to username --- api/index.js | 3 ++- api/users.js | 16 ++++++++++++++++ database/seed.js | 8 ++++---- database/user.js | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 api/users.js diff --git a/api/index.js b/api/index.js index f08162e..25fea5f 100644 --- a/api/index.js +++ b/api/index.js @@ -1,7 +1,8 @@ const express = require("express"); const router = express.Router(); const testDbRouter = require("./test-db"); +const usersRouter = require("./users") router.use("/test-db", testDbRouter); - +router.use("/users", usersRouter); module.exports = router; diff --git a/api/users.js b/api/users.js new file mode 100644 index 0000000..9d8192c --- /dev/null +++ b/api/users.js @@ -0,0 +1,16 @@ +const express = require("express") +const router = express.Router(); +const { User } = require("../database"); + +router.get("/", async (req, res) => { + try { + const users = await User.findAll({ + attributes: { exclude: ["password_hash"] } + }); + res.json(users); + } catch (err) { + res.status(500).json({ error: "Failed to fetch users" }); + } +}); + +module.exports = router; \ No newline at end of file diff --git a/database/seed.js b/database/seed.js index d23ee7e..a61cbcd 100644 --- a/database/seed.js +++ b/database/seed.js @@ -7,10 +7,10 @@ const seed = async () => { await db.sync({ force: true }); // Drop and recreate tables const users = await User.bulkCreate([ - { name: "jeramy", password_hash: User.hashPassword("123"), email: "jeramy@gmail.com" }, - { name: "aiyanna", password_hash: User.hashPassword("456"), email: "aiyanna@gmail.com" }, - { name: "emmanuel", password_hash: User.hashPassword("789"), email: "emmanuel@gmail.com" }, - { name: "olivia", password_hash: User.hashPassword("101112"), email: "olivia@gmail.com" }, + { username: "jeramy", password_hash: User.hashPassword("123456"), email: "jeramy@gmail.com" }, + { username: "aiyanna", password_hash: User.hashPassword("456"), email: "aiyanna@gmail.com" }, + { username: "emmanuel", password_hash: User.hashPassword("789"), email: "emmanuel@gmail.com" }, + { username: "olivia", password_hash: User.hashPassword("101112"), email: "olivia@gmail.com" }, ]); console.log(`👤 Created ${users.length} users`); diff --git a/database/user.js b/database/user.js index 665ca55..fc63778 100644 --- a/database/user.js +++ b/database/user.js @@ -9,7 +9,7 @@ const User = db.define("user", { primaryKey: true, }, - name: { + username: { type: DataTypes.STRING, allowNull: false, }, From ccbe0fc906d1ece0b72b150d5a5af10acdeef59b Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Thu, 31 Jul 2025 15:24:48 -0400 Subject: [PATCH 06/17] get user by id and get all user routes added --- api/users.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/users.js b/api/users.js index 9d8192c..abe1d25 100644 --- a/api/users.js +++ b/api/users.js @@ -13,4 +13,16 @@ router.get("/", async (req, res) => { } }); +router.get("/:id", async (req, res) => { + try { + const user = await User.findByPk(req.params.id, { + attributes: { exclude: ["password_hash"] } + }); + + res.json(user); + } catch (err) { + res.status(500).json({ error: "Failed to fetch user" }) + } +}); + module.exports = router; \ No newline at end of file From 32b34e8934763390a235609d49fa19d4e2e02288 Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Thu, 31 Jul 2025 15:48:22 -0400 Subject: [PATCH 07/17] changing database names --- database/db.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/db.js b/database/db.js index b251a9d..3b580f1 100644 --- a/database/db.js +++ b/database/db.js @@ -3,7 +3,7 @@ const { Sequelize } = require("sequelize"); const pg = require("pg"); // Feel free to rename the database to whatever you want! -const dbName = "capstone-1"; +const dbName = "capstone-2"; const db = new Sequelize( process.env.DATABASE_URL || `postgres://localhost:5432/${dbName}`, From 612bd5a0a14ec6c0b78cc697357d44b6828c7786 Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Fri, 1 Aug 2025 13:36:22 -0400 Subject: [PATCH 08/17] addded echo_visibility model so users can customize who can see their echoes --- database/echo_visibility.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 database/echo_visibility.js diff --git a/database/echo_visibility.js b/database/echo_visibility.js new file mode 100644 index 0000000..a465273 --- /dev/null +++ b/database/echo_visibility.js @@ -0,0 +1,26 @@ +const { DataTypes} = require("sequelize"); +const db = require("./db"); + +const Echo_visibility = db.define("echo_visibility", { + echo_id: { + type: DataTypes.INTEGER, + primaryKey: true, + allowNull: false, + }, + + scope: { + type: DataTypes.ENUM("self", "friends", "public", "custom"), + allowNull: false, + + }, + + note: { + type: DataTypes.TEXT, + allowNull: true + } +}, { + tableName: 'echo_visibility', + timestamps: false, +}); + +module.exports = Echo_visibility; From 525ded48f293cc50828fc1bd11be1b145b406413 Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Fri, 1 Aug 2025 14:37:41 -0400 Subject: [PATCH 09/17] update some models with references and added echo_recipients model --- database/echo_recipients.js | 29 +++++++++++++++++++++++++++++ database/echoes.js | 12 ++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 database/echo_recipients.js diff --git a/database/echo_recipients.js b/database/echo_recipients.js new file mode 100644 index 0000000..2e3223e --- /dev/null +++ b/database/echo_recipients.js @@ -0,0 +1,29 @@ +const { DataTypes } = require("sequelize"); +const db = require("./db"); + +const Echo_recipients = db.define("echo_recipients", { + echo_id: { + type: DataTypes.INTEGER, + primaryKey: true, + allowNull: false, + references: { + model: 'echoes', // target table name + key: 'id' + }, + }, + + recipient_id: { + type: DataTypes.INTEGER, + primaryKey: true, + allowNull: false, + references: { + model: 'users', // target table name + key: 'id' + }, + } +}, { + tableName: 'echo_recipients', + timestamps: false +}); + +module.exports = Echo_recipients; diff --git a/database/echoes.js b/database/echoes.js index 1a166ac..bb471e1 100644 --- a/database/echoes.js +++ b/database/echoes.js @@ -1,16 +1,20 @@ const { DataTypes } = require("sequelize"); const db = require("./db"); -const Echoes = db.define("user", { +const Echoes = db.define("echoes", { id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, }, - sender_id: { + sender_id: { type: DataTypes.INTEGER, - allowNull: false + allowNull: false, + references: { + model: 'users', // target table + key: 'id' + } }, type: { @@ -49,7 +53,7 @@ const Echoes = db.define("user", { } }, { - tableName: 'Echoes', + tableName: 'echoes', timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', From b5e3a2a534f9e97e283e50b142de82d6c09708e8 Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Fri, 1 Aug 2025 15:20:23 -0400 Subject: [PATCH 10/17] added tags model --- database/tags.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 database/tags.js diff --git a/database/tags.js b/database/tags.js new file mode 100644 index 0000000..93e9352 --- /dev/null +++ b/database/tags.js @@ -0,0 +1,21 @@ +const { DataTypes } = require("sequelize"); +const db = require("./db"); + +const Tags = db.define("tags", { + id: { + type: DataTypes.INTEGER, + primaryKey: true, + allowNull: false, + autoIncrement: true, // auto generated tags IDs + }, + + name: { + type: DataTypes.TEXT, + allowNull: false, + } +}, { + tableName: 'tags', + timestamps: true +}); + +module.exports = Tags; From bbf270daec19d6c946d35b4f2a5f12e2b23ea8ad Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Fri, 1 Aug 2025 15:51:31 -0400 Subject: [PATCH 11/17] added echo tags model --- database/echo_tags.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 database/echo_tags.js diff --git a/database/echo_tags.js b/database/echo_tags.js new file mode 100644 index 0000000..8d4fb0e --- /dev/null +++ b/database/echo_tags.js @@ -0,0 +1,29 @@ +const { DataTypes } = require("sequelize"); +const db = require("./db"); + +const Echo_tags = db.define('echo_tags', { + echo_id: { + type: DataTypes.INTEGER, + allowNull: false, + primaryKey: true, + references: { + model: "echoes", // target table + key: "id" + } + }, + + tag_id: { + type: DataTypes.INTEGER, + allowNull: false, + primaryKey: true, + references: { + model: "tags", + key: "id" + } + } +}, { + tableName: 'echo_tas', + timestamps: false +}); + +module.exports = Echo_tags; From 25dc26d30711db2be6849e96dd839f939fd163a6 Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Mon, 4 Aug 2025 11:07:36 -0400 Subject: [PATCH 12/17] media model created for image/video/audio uploads --- database/media.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 database/media.js diff --git a/database/media.js b/database/media.js new file mode 100644 index 0000000..d3492db --- /dev/null +++ b/database/media.js @@ -0,0 +1,55 @@ +const { DataTypes } = require("sequelize"); +const db = require("/.db"); + +const Media = db.define("media", { + id: { + type: DataTypes.INTEGER, + primaryKey: true, + autoIncrement: true + }, + + echo_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: 'echoes', + key: 'id' + } + }, + + type: { + type: DataTypes.ENUM('image', 'audio', 'video'), + allowNull: false, + }, + + url: { + type: DataTypes.STRING, + allowNull: false, + validate: { + isUrl: true + } + }, + + file_size: { + type: DataTypes.INTEGER, + allowNull: false + }, + + duration_seconds: { + // only applies to audio or video + type: DataTypes.INTEGER, + allowNull: true + }, + + thumbnail_url: { + // optional thumbnail + type: DataTypes.STRING, + allowNull: true + } +}, { + timestamps: true, + createdAt: 'created_at', + updatedAt: 'updated_at' +}); + +module.exports = Media; From 952c8c753c1d9e1da8937135456dd6ea1a511ed3 Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Mon, 4 Aug 2025 11:28:36 -0400 Subject: [PATCH 13/17] added reports model for user reports --- database/reports.js | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 database/reports.js diff --git a/database/reports.js b/database/reports.js new file mode 100644 index 0000000..d83737f --- /dev/null +++ b/database/reports.js @@ -0,0 +1,56 @@ +const { DataTypes } = require("sequelize"); +const db = require("./db"); + +const Reports = db.define("reports", { + id: { + primaryKey: true, + type: DataTypes.INTEGER, + autoIncrement: true + }, + + echo_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: 'echoes', + key: 'id' + } + }, + + reporter_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: 'users', + key: 'id' + } + }, + + type: { + type: DataTypes.ENUM('spam', 'harrassment', 'hate_speech', 'explicit', 'other'), + allowNull: false, + }, + + reasons: { + // option message for report + type: DataTypes.TEXT, + allowNull: true + }, + + status: { + type: DataTypes.ENUM('pending', 'reviewed', 'dismissed'), + allowNull: false, + defaultValue: 'pending' + }, + + reviewed_at: { + type: DataTypes.DATE, + allowNull: true + } +}, { + timestamps: true, + createdAt: 'created_at', + updatedAt: 'updated_at', +}); + +module.exports = Reports; \ No newline at end of file From 2053cc9a48c6efca35792992e4c3c59a33c1609a Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Mon, 4 Aug 2025 11:53:59 -0400 Subject: [PATCH 14/17] friends model so users can add one another as friends --- database/echo_tags.js | 2 +- database/friends.js | 48 +++++++++++++++++++++++++++++++++++++++++++ database/reactions.js | 0 database/replies.js | 0 database/user.js | 1 + 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 database/friends.js create mode 100644 database/reactions.js create mode 100644 database/replies.js diff --git a/database/echo_tags.js b/database/echo_tags.js index 8d4fb0e..f018005 100644 --- a/database/echo_tags.js +++ b/database/echo_tags.js @@ -22,7 +22,7 @@ const Echo_tags = db.define('echo_tags', { } } }, { - tableName: 'echo_tas', + tableName: 'echo_tags', timestamps: false }); diff --git a/database/friends.js b/database/friends.js new file mode 100644 index 0000000..6ce2209 --- /dev/null +++ b/database/friends.js @@ -0,0 +1,48 @@ +const { DataTypes } = require("sequelize"); +const db = require("./db"); + +const Friends = db.define("friends", { + id: { + primaryKey: true, + type: DataTypes.INTEGER, + autoIncrement: true + }, + + user_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: 'users', + key: 'id' + } + }, + + friend_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: 'users', + key: 'id' + } + }, + + status: { + type: DataTypes.ENUM('pending', 'accepted', 'blocked'), + allowNull: false, + defaultValue: 'pending' + } +}, { + tableName: 'friends', + timestamps: true, + createdAt: 'created_at', + updatedAt: 'updated_at', + indexes: [ + { + unique: true, + fields: ['user_id', 'friend_id'], + name: 'unique_user_friend_pair' + } + ] +}); + +module.exports = Friends; \ No newline at end of file diff --git a/database/reactions.js b/database/reactions.js new file mode 100644 index 0000000..e69de29 diff --git a/database/replies.js b/database/replies.js new file mode 100644 index 0000000..e69de29 diff --git a/database/user.js b/database/user.js index fc63778..2bf92ad 100644 --- a/database/user.js +++ b/database/user.js @@ -12,6 +12,7 @@ const User = db.define("user", { username: { type: DataTypes.STRING, allowNull: false, + unique: true }, bio: { From 134e4264fd52718c4a4e42f48caa349c04991fed Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Mon, 4 Aug 2025 13:19:17 -0400 Subject: [PATCH 15/17] replies model for user replies to echos and commments --- database/media.js | 23 +++++++++++++++++++++-- database/replies.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/database/media.js b/database/media.js index d3492db..8d4afef 100644 --- a/database/media.js +++ b/database/media.js @@ -10,13 +10,22 @@ const Media = db.define("media", { echo_id: { type: DataTypes.INTEGER, - allowNull: false, + allowNull: true, references: { model: 'echoes', key: 'id' } }, + reply_id: { + type: DataTypes.INTEGER, + allowNull: true, + references: { + model: 'replies', + key: 'id' + } + }, + type: { type: DataTypes.ENUM('image', 'audio', 'video'), allowNull: false, @@ -49,7 +58,17 @@ const Media = db.define("media", { }, { timestamps: true, createdAt: 'created_at', - updatedAt: 'updated_at' + updatedAt: 'updated_at', + validate: { + eitherEchoOrReply() { + if (!this.echo_id && !this.reply_id) { + throw new Error('Media must belong to either an echo or reply.'); + } + if (this.echo_id && this.reply_id) { + throw new Error('Media cannot belong to both an echo and a reply.'); + } + } + } }); module.exports = Media; diff --git a/database/replies.js b/database/replies.js index e69de29..9f8f7d2 100644 --- a/database/replies.js +++ b/database/replies.js @@ -0,0 +1,44 @@ +const { DataTypes } = require('sequelize'); +const db = require('./db'); + +const Replies = db.define('replies', { + id: { + primaryKey: true, + autoIncrement: true, + type: DataTypes.INTEGER + }, + + echo_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: 'echoes', + key: 'id' + } + }, + + user_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: 'users', + key: 'id' + } + }, + + parent_reply_id: { + type: DataTypes.INTEGER, + allowNull: true, + references: { + model: 'replies', + key: 'id' + } + } +}, { + tableName: 'replies', + timestamps: true, + createdAt: 'created_at', + updatedAt: 'updated_at' +}); + +module.exports = Replies; \ No newline at end of file From 78f682eb1f65fa067cce3cea7295836f6c87cc39 Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Mon, 4 Aug 2025 13:27:19 -0400 Subject: [PATCH 16/17] reaction model allows users to have one reaction to an echo --- database/reactions.js | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/database/reactions.js b/database/reactions.js index e69de29..3d8d87d 100644 --- a/database/reactions.js +++ b/database/reactions.js @@ -0,0 +1,44 @@ +const { DataTypes } = require('sequelize'); +const db = require('./db'); + +const Reactions = db.define('reactions', { + id: { + primaryKey: true, + type: DataTypes.INTEGER, + autoIncrement: true + }, + + echo_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: 'echoes', + key: 'id' + } + }, + + user_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: 'users', + key: 'id' + } + }, + + type: { + type: DataTypes.ENUM('sad', 'funny', 'happy'), + allowNull: false + } +}, { + timestamps: true, + createdAt: 'created_at', + updatedAt: 'updated_at', + indexes: [{ + unique: true, + fields: ['user_id', 'echo_id'], + name: 'unique_user_echo_reaction_pair' + }] +}); + +module.exports = Reactions; From 3d3ebaed270090dc020597117f715657c8555fc0 Mon Sep 17 00:00:00 2001 From: jeramyleon Date: Mon, 4 Aug 2025 13:42:43 -0400 Subject: [PATCH 17/17] done with models, starting associations now --- database/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/database/index.js b/database/index.js index e498df6..6fbf6c4 100644 --- a/database/index.js +++ b/database/index.js @@ -1,5 +1,11 @@ const db = require("./db"); const User = require("./user"); +const Echoes = require('./echoes'); +const Echo_visibility = require('./echo_visibility'); +const Echo_recipients = require('./echo_recipients'); +const Echo_tags = require('./echo_tags'); + + module.exports = { db,