Skip to content

Commit

Permalink
Merge pull request #5108 from NMDSdevopsServiceAdm/fix/indexMigration
Browse files Browse the repository at this point in the history
change migration
  • Loading branch information
Richard-Pentecost authored Jul 21, 2022
2 parents 94801ee + b927f59 commit 70e78af
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
28 changes: 15 additions & 13 deletions migrations/20220718113815-workerAuditTableAddIndexForUsername.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

module.exports = {
up: async (queryInterface) => {
await queryInterface.addIndex(
{
tableName: 'WorkerAudit',
schema: 'cqc',
},
{
fields: ['Username'],
},
{
name: 'worker_audit__username_idx',
},
);
await queryInterface.sequelize.transaction(async (transaction) => {
await Promise.all([
queryInterface.sequelize.query('DROP INDEX IF EXISTS cqc."worker_audit__username";', { transaction }),
queryInterface.addIndex(
{
tableName: 'WorkerAudit',
schema: 'cqc',
},
{
fields: ['Username'],
},
),
]);
});
},

down: async (queryInterface) => {
Expand All @@ -22,7 +24,7 @@ module.exports = {
tableName: 'WorkerAudit',
schema: 'cqc',
},
'cqc."worker_audit__username_idx"',
'cqc."worker_audit__username"',
);
},
};
12 changes: 1 addition & 11 deletions server/routes/accounts/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,7 @@ const finishAddUser = async (req, res) => {
};

const deleteUser = async (req, res) => {
console.log('********************** user.js accounts/deleteUser ******************************');

const userId = req.params.userid;
console.log('##### deleteUser - userId:', userId);

const uuidRegex = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/;
if (!uuidRegex.test(userId.toUpperCase())) {
Expand All @@ -638,30 +635,23 @@ const deleteUser = async (req, res) => {
const thisUser = new User.User(userId);

try {
console.log('##### deleteUser - inside try');
if (await thisUser.restore(userId, null, false)) {
console.log('##### deleteUser - restore succeeded');
if (thisUser.username && thisUser.username == req.username) {
return res.status(400).send('Cannot delete own user account');
}

if (thisUser._isPrimary) {
console.log('##### deleteUser - user is primary');
return res.status(400).send('Cannot delete primary account');
}

console.log('restored about to delete');
await thisUser.delete(req.username);
console.log('##### deleteUser - delete completed');

return res.status(204).send();
} else {
console.log('##### deleteUser - restore failed');
console.log('404 not found that user');
return res.status(404).send('Not Found');
}
} catch (err) {
console.log('##### deleteUser - error');
console.log(err);
const thisError = new User.UserExceptions.UserRestoreException(
thisUser.id,
thisUser.uid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { WindowRef } from '@core/services/window.ref';
import {
AdminManagerUser,
AdminUser,
MockAdminUsersService,
PendingAdminManager,
PendingAdminUser,
} from '@core/test-utils/admin/MockAdminUsersService';
Expand Down Expand Up @@ -60,6 +61,10 @@ describe('AdminAccountViewComponent', () => {
provide: BreadcrumbService,
useClass: MockBreadcrumbService,
},
{
provide: AdminUsersService,
useClass: MockAdminUsersService,
},
{
provide: ActivatedRoute,
useValue: {
Expand Down Expand Up @@ -224,7 +229,7 @@ describe('AdminAccountViewComponent', () => {
it('should call deleteAdminUserDetails with the the user id', async () => {
const { component, fixture, getByText, adminUsersService } = await setup();

const deleteAdminSpy = spyOn(adminUsersService, 'deleteAdminUserDetails');
const deleteAdminSpy = spyOn(adminUsersService, 'deleteAdminUserDetails').and.returnValue(of({}));
const deleteLink = getByText('Delete this admin user');
fireEvent.click(deleteLink);
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ describe('NewTrainingAndQualificationsRecordComponent', () => {

const yesterday = new Date();
const tomorrow = new Date();
const activeDate = new Date();

yesterday.setDate(yesterday.getDate() - 1);
tomorrow.setDate(tomorrow.getDate() + 1);
activeDate.setDate(activeDate.getDate() + 93); // 3 months in the future

async function setup(
otherJob = false,
Expand Down Expand Up @@ -77,10 +79,10 @@ describe('NewTrainingAndQualificationsRecordComponent', () => {
{
accredited: true,
completed: new Date('10/20/2021'),
expires: new Date('10/20/2022'),
expires: activeDate,
title: 'Health training',
trainingCategory: { id: 1, category: 'Health' },
trainingStatus: 3,
trainingStatus: 0,
uid: 'someHealthuid',
},
],
Expand Down

0 comments on commit 70e78af

Please sign in to comment.