Skip to content
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
33 changes: 33 additions & 0 deletions knex/migrations/20251109095712_remove_orphan_mentor_role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function(knex) {
return knex.transaction(async (trx) => {
const mentorRole = await trx('roles').where({ role_name: 'mentor' }).first();

if (!mentorRole) {
console.warn('Mentor role not found — skipping cleanup.');

Check warning on line 10 in knex/migrations/20251109095712_remove_orphan_mentor_role.js

View workflow job for this annotation

GitHub Actions / eslint / setup

Unexpected console statement
return;
}

await trx('user_roles')
.where('role_id', mentorRole.id)
.whereIn('user_id', function () {
this.select('user_id')
.from('user_roles')
.where('role_id', mentorRole.id)
.whereNotIn('user_id', trx('mentors').select('user_id'));
})
.del();
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function(_) {
// This migration is not reversible because deleted rows cannot be recovered.
console.warn('⚠️ This migration is not reversible (cannot recover deleted rows)');

Check warning on line 32 in knex/migrations/20251109095712_remove_orphan_mentor_role.js

View workflow job for this annotation

GitHub Actions / eslint / setup

Unexpected console statement
};
1 change: 0 additions & 1 deletion services/mentor_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ async function createMentor(userId, mentorData) {
status: 'pending',
about: mentorData.about,
contact: mentorData.contact,
tags: mentorData.tags
};

const mentorInfo = await repo.createMentor(mentor);
Expand Down
3 changes: 1 addition & 2 deletions tests/services/mentor_service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ describe('Mentor Service', () => {
user_id: defaultUserId,
status: MENTOR_STATUSES.pending,
about: mentorData.about,
contact: mentorData.contact,
tags: mentorData.tags
contact: mentorData.contact
});
expect(tagsRepo.updateMentorTags).toHaveBeenCalledWith(createdMentor.id, mentorData.tags);
expect(rolesService.getAdminEmails).toHaveBeenCalled();
Expand Down
Loading