imageFilenames and imageFilename, backend integration tests, frontend tests, removed username references

This commit is contained in:
jackiettran
2025-11-26 23:13:23 -05:00
parent f2d3aac029
commit 11593606aa
52 changed files with 2815 additions and 150 deletions

View File

@@ -101,12 +101,14 @@ router.post(
phone,
});
// Link alpha invitation to user
await alphaInvitation.update({
usedBy: user.id,
usedAt: new Date(),
status: "active",
});
// Link alpha invitation to user (only if alpha testing is enabled)
if (alphaInvitation) {
await alphaInvitation.update({
usedBy: user.id,
usedAt: new Date(),
status: "active",
});
}
// Generate verification token and send email
await user.generateVerificationToken();
@@ -367,7 +369,7 @@ router.post(
lastName,
authProvider: "google",
providerId: googleId,
profileImage: picture,
imageFilename: picture,
isVerified: true,
verifiedAt: new Date(),
});
@@ -434,7 +436,7 @@ router.post(
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
profileImage: user.profileImage,
imageFilename: user.imageFilename,
isVerified: user.isVerified,
role: user.role,
},

View File

@@ -27,7 +27,7 @@ const upload = multer({
router.post(
"/:rentalId",
authenticateToken,
upload.array("photos"),
upload.array("imageFilenames"),
async (req, res) => {
try {
const { rentalId } = req.params;
@@ -35,13 +35,13 @@ router.post(
const userId = req.user.id;
// Get uploaded file paths
const photos = req.files ? req.files.map((file) => file.path) : [];
const imageFilenames = req.files ? req.files.map((file) => file.path) : [];
const conditionCheck = await ConditionCheckService.submitConditionCheck(
rentalId,
checkType,
userId,
photos,
imageFilenames,
notes
);
@@ -50,7 +50,7 @@ router.post(
rentalId,
checkType,
userId,
photoCount: photos.length,
photoCount: imageFilenames.length,
});
res.status(201).json({

View File

@@ -21,7 +21,7 @@ const buildCommentTree = (comments, isAdmin = false) => {
// Sanitize deleted comments for non-admin users
if (commentJson.isDeleted && !isAdmin) {
commentJson.content = '';
commentJson.images = [];
commentJson.imageFilenames = [];
}
commentMap[comment.id] = { ...commentJson, replies: [] };
@@ -252,7 +252,7 @@ router.post('/posts', authenticateToken, uploadForumPostImages, async (req, res,
}
// Extract image filenames if uploaded
const images = req.files ? req.files.map(file => file.filename) : [];
const imageFilenames = req.files ? req.files.map(file => file.filename) : [];
// Initialize location fields
let latitude = null;
@@ -313,7 +313,7 @@ router.post('/posts', authenticateToken, uploadForumPostImages, async (req, res,
content,
category,
authorId: req.user.id,
images,
imageFilenames,
zipCode: zipCode || null,
latitude,
longitude
@@ -936,14 +936,14 @@ router.post('/posts/:id/comments', authenticateToken, uploadForumCommentImages,
}
// Extract image filenames if uploaded
const images = req.files ? req.files.map(file => file.filename) : [];
const imageFilenames = req.files ? req.files.map(file => file.filename) : [];
const comment = await ForumComment.create({
postId: req.params.id,
authorId: req.user.id,
content,
parentCommentId: parentCommentId || null,
images
imageFilenames
});
// Increment comment count and update post's updatedAt to reflect activity
@@ -955,7 +955,7 @@ router.post('/posts/:id/comments', authenticateToken, uploadForumCommentImages,
{
model: User,
as: 'author',
attributes: ['id', 'username', 'firstName', 'lastName', 'email']
attributes: ['id', 'firstName', 'lastName', 'email']
}
]
});
@@ -1261,7 +1261,7 @@ router.delete('/admin/posts/:id', authenticateToken, requireAdmin, async (req, r
{
model: User,
as: 'author',
attributes: ['id', 'username', 'firstName', 'lastName', 'email']
attributes: ['id', 'firstName', 'lastName', 'email']
}
]
});
@@ -1380,7 +1380,7 @@ router.delete('/admin/comments/:id', authenticateToken, requireAdmin, async (req
{
model: User,
as: 'author',
attributes: ['id', 'username', 'firstName', 'lastName', 'email']
attributes: ['id', 'firstName', 'lastName', 'email']
}
]
});
@@ -1512,7 +1512,7 @@ router.patch('/admin/posts/:id/close', authenticateToken, requireAdmin, async (r
{
model: User,
as: 'author',
attributes: ['id', 'username', 'firstName', 'lastName', 'email']
attributes: ['id', 'firstName', 'lastName', 'email']
}
]
});
@@ -1545,7 +1545,7 @@ router.patch('/admin/posts/:id/close', authenticateToken, requireAdmin, async (r
(async () => {
try {
const admin = await User.findByPk(req.user.id, {
attributes: ['id', 'username', 'firstName', 'lastName', 'email']
attributes: ['id', 'firstName', 'lastName', 'email']
});
// Get all unique participants (author + commenters)

View File

@@ -20,7 +20,7 @@ router.get('/', authenticateToken, async (req, res, next) => {
{
model: User,
as: 'sender',
attributes: ['id', 'firstName', 'lastName', 'profileImage']
attributes: ['id', 'firstName', 'lastName', 'imageFilename']
}
],
order: [['createdAt', 'DESC']]
@@ -61,12 +61,12 @@ router.get('/conversations', authenticateToken, async (req, res, next) => {
{
model: User,
as: 'sender',
attributes: ['id', 'firstName', 'lastName', 'profileImage']
attributes: ['id', 'firstName', 'lastName', 'imageFilename']
},
{
model: User,
as: 'receiver',
attributes: ['id', 'firstName', 'lastName', 'profileImage']
attributes: ['id', 'firstName', 'lastName', 'imageFilename']
}
],
order: [['createdAt', 'DESC']]
@@ -147,7 +147,7 @@ router.get('/sent', authenticateToken, async (req, res, next) => {
{
model: User,
as: 'receiver',
attributes: ['id', 'firstName', 'lastName', 'profileImage']
attributes: ['id', 'firstName', 'lastName', 'imageFilename']
}
],
order: [['createdAt', 'DESC']]
@@ -186,12 +186,12 @@ router.get('/:id', authenticateToken, async (req, res, next) => {
{
model: User,
as: 'sender',
attributes: ['id', 'firstName', 'lastName', 'profileImage']
attributes: ['id', 'firstName', 'lastName', 'imageFilename']
},
{
model: User,
as: 'receiver',
attributes: ['id', 'firstName', 'lastName', 'profileImage']
attributes: ['id', 'firstName', 'lastName', 'imageFilename']
}
]
});
@@ -253,20 +253,20 @@ router.post('/', authenticateToken, uploadMessageImage, async (req, res, next) =
}
// Extract image filename if uploaded
const imagePath = req.file ? req.file.filename : null;
const imageFilename = req.file ? req.file.filename : null;
const message = await Message.create({
senderId: req.user.id,
receiverId,
content,
imagePath
imageFilename
});
const messageWithSender = await Message.findByPk(message.id, {
include: [{
model: User,
as: 'sender',
attributes: ['id', 'firstName', 'lastName', 'profileImage']
attributes: ['id', 'firstName', 'lastName', 'imageFilename']
}]
});
@@ -398,7 +398,7 @@ router.get('/images/:filename',
// Verify user is sender or receiver of a message with this image
const message = await Message.findOne({
where: {
imagePath: filename,
imageFilename: filename,
[Op.or]: [
{ senderId: req.user.id },
{ receiverId: req.user.id }

View File

@@ -211,8 +211,8 @@ router.post('/profile/image', authenticateToken, (req, res) => {
try {
// Delete old profile image if exists
const user = await User.findByPk(req.user.id);
if (user.profileImage) {
const oldImagePath = path.join(__dirname, '../uploads/profiles', user.profileImage);
if (user.imageFilename) {
const oldImagePath = path.join(__dirname, '../uploads/profiles', user.imageFilename);
try {
await fs.unlink(oldImagePath);
} catch (unlinkErr) {
@@ -227,7 +227,7 @@ router.post('/profile/image', authenticateToken, (req, res) => {
// Update user with new image filename
await user.update({
profileImage: req.file.filename
imageFilename: req.file.filename
});
const reqLogger = logger.withRequestId(req.id);