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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
"express-validator": "^6.15.0",
"graphql": "^15.8.0",
"graphql-tag": "^2.12.6",
"helmet": "^6.1.1",
"helmet": "^6.1.2",
"jsonwebtoken": "^9.0.0",
"moment": "^2.29.4",
"mongodb": "^5.2.0",
"mongoose": "^6.10.1",
"mongoose": "^7.0.3",
"pino": "^8.11.0",
"pino-pretty": "^10.0.0",
"swagger-ui-express": "^4.6.2",
Expand Down
19 changes: 5 additions & 14 deletions src/models/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import moment from 'moment';
import bcryptjs from 'bcryptjs';
import crypto from 'crypto';
import jwt from 'jsonwebtoken';
import Domain from './domain';
import { Team } from './team';
import { notifyAcCreation, notifyAcDeletion } from '../external/switcher-api-facade';

Expand Down Expand Up @@ -180,11 +179,12 @@ adminSchema.statics.createThirdPartyAccount = async (
_avatar: userInfo.avatar,
password: hash
});

await admin.save();
} else {
admin._avatar = userInfo.avatar;
}


admin.name = userInfo.name;
admin._avatar = userInfo.avatar;
return admin;
};

Expand All @@ -210,17 +210,8 @@ adminSchema.post('save', function(error, _doc, next) {
next(error);
});

adminSchema.pre('remove', async function (next) {
const ObjectId = (require('mongoose').Types.ObjectId);

adminSchema.pre('deleteOne', { document: true, query: false }, async function (next) {
const admin = this;
const domains = await Domain.find({ owner: new ObjectId(admin._id) }).exec();

if (domains) {
for (const domain of domains)
await domain.remove();
}

const teams = await Team.find({ members: admin._id }).exec();
for (const team of teams) {
let indexMmeber = team.members.indexOf(admin._id);
Expand Down
2 changes: 1 addition & 1 deletion src/models/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ componentSchema.pre('validate', async function (next) {
next();
});

componentSchema.pre('remove', async function (next) {
componentSchema.pre('deleteOne', { document: true, query: false }, async function (next) {
const component = this;

const configsToRemoveFrom = await Config.find({ components: { $in: [component._id] } }).exec();
Expand Down
2 changes: 1 addition & 1 deletion src/models/config-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ configStrategySchema.options.toJSON = {
}
};

configStrategySchema.pre('remove', async function (next) {
configStrategySchema.pre('deleteOne', { document: true, query: false }, async function (next) {
const strategyConfig = this;
await History.deleteMany({ domainId: strategyConfig.domain,
elementId: strategyConfig._id }).exec();
Expand Down
4 changes: 2 additions & 2 deletions src/models/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ configSchema.virtual('configStrategy', {
foreignField: 'config'
});

configSchema.pre('remove', async function (next) {
configSchema.pre('deleteOne', { document: true, query: false }, async function (next) {
const config = this;

const strategies = await ConfigStrategy.find({ config: config._id }).exec();
if (strategies) {
for (const strategy of strategies) {
await strategy.remove();
await Promise.resolve(strategy.deleteOne());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/models/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@ domainSchema.options.toJSON = {
}
};

domainSchema.pre('remove', async function (next) {
domainSchema.pre('deleteOne', { document: true, query: false }, async function (next) {
const domain = this;
const groups = await GroupConfig.find({ domain: domain._id }).exec();

if (groups) {
for (const group of groups) {
await group.remove();
await Promise.resolve(group.deleteOne());
}
}

const teams = await Team.find({ domain: domain._id }).exec();
if (teams) {
for (const team of teams) {
await team.remove();
await Promise.resolve(team.deleteOne());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/models/group-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ groupConfigSchema.virtual('config', {
foreignField: 'group'
});

groupConfigSchema.pre('remove', async function (next) {
groupConfigSchema.pre('deleteOne', { document: true, query: false }, async function (next) {
const group = this;
const configs = await Config.find({ group: group._id }).exec();

if (configs) {
for (const config of configs) {
await config.remove();
await Promise.resolve(config.deleteOne());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ teamSchema.pre('validate', async function (next) {
next();
});

teamSchema.pre('remove', async function (next) {
teamSchema.pre('deleteOne', { document: true, query: false }, async function (next) {
const team = this;
await Permission.deleteMany({ _id: { $in: team.permissions } }).exec();

Expand Down
2 changes: 1 addition & 1 deletion src/routers/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ router.delete('/environment/:id', auth, [
], validate, async (req, res) => {
try {
const environment = await Services.deleteEnvironment(req.params.id, req.admin);
await environment.remove();
await environment.deleteOne();
res.send(environment);
} catch (e) {
responseException(res, e, 400);
Expand Down
2 changes: 1 addition & 1 deletion src/services/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@ export async function deleteAccount(admin) {
`This account has ${domains} Domain(s) that must be either deleted or transfered to another account.`);
}

return admin.remove();
return admin.deleteOne();
}
2 changes: 1 addition & 1 deletion src/services/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function deleteComponent(id, admin) {
let component = await getComponentById(id);
component = await verifyOwnership(
admin, component, component.domain, ActionTypes.DELETE, RouterTypes.COMPONENT);
return component.remove();
return component.deleteOne();
}

export async function generateApiKey(id, admin) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/config-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export async function createStrategy(args, admin) {
export async function deleteStrategy(id, admin) {
let configStrategy = await getStrategyById(id);
configStrategy = await verifyOwnership(admin, configStrategy, configStrategy.domain, ActionTypes.DELETE, RouterTypes.STRATEGY);

await configStrategy.remove();
await configStrategy.deleteOne();
updateDomainVersion(configStrategy.domain);

return configStrategy;
Expand Down
4 changes: 2 additions & 2 deletions src/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function deleteConfig(id, admin) {
let config = await getConfigById(id);
config = await verifyOwnership(admin, config, config.domain, ActionTypes.DELETE, RouterTypes.CONFIG);

await config.remove();
await config.deleteOne();
updateDomainVersion(config.domain);

return config;
Expand Down Expand Up @@ -224,7 +224,7 @@ export async function removeComponent(id, args, admin) {

export async function updateComponent(id, args, admin) {
const config = await verifyAddComponentInput(id, admin);
const componentIds = args.components.map(component => mongoose.Types.ObjectId(component));
const componentIds = args.components.map(component => new mongoose.Types.ObjectId(component));
const components = await getComponents({ _id: { $in: componentIds } });

if (components.length != args.components.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function deleteDomainHistory(id, admin) {
export async function deleteDomain(id, admin) {
let domain = await getDomainById(id);
domain = await verifyOwnership(admin, domain, domain._id, ActionTypes.DELETE, RouterTypes.DOMAIN);
return domain.remove();
return domain.deleteOne();
}

export async function transferDomain(args, admin) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export async function deleteEnvironment(id, admin) {
environment = await verifyOwnership(admin, environment, environment.domain, ActionTypes.DELETE, RouterTypes.ENVIRONMENT);

await removeEnvironmentFromElements(environment);
return environment.remove();
return environment.deleteOne();
}

export async function recoverEnvironment(id, admin) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/group-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function deleteGroup(id, admin) {
let groupconfig = await getGroupConfigById(id);
groupconfig = await verifyOwnership(admin, groupconfig, groupconfig.domain, ActionTypes.DELETE, RouterTypes.GROUP);

await groupconfig.remove();
await groupconfig.deleteOne();
updateDomainVersion(groupconfig.domain);

return groupconfig;
Expand Down
2 changes: 1 addition & 1 deletion src/services/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function deletePermission(id, admin) {
team.save();
});

return permission.remove();
return permission.deleteOne();
}

export async function addValue(args, id, admin) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function deleteSlackInstallation(slack) {
await domain.save();
}

return slack.remove();
return slack.deleteOne();
}

export async function getSlackOrError(where) {
Expand Down
8 changes: 4 additions & 4 deletions src/services/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function updateTeam(args, id, admin) {

export async function deleteTeam(id, admin) {
const team = await verifyRequestedTeam(id, admin, ActionTypes.DELETE);
return team.remove();
return team.deleteOne();
}

export async function inviteMember(id, email, admin) {
Expand Down Expand Up @@ -136,9 +136,9 @@ export async function acceptInvite(request_id, admin) {

if (team.length) {
await addMemberToTeam(admin, team[0]);
teamInvite.remove();
teamInvite.deleteOne();
} else {
await teamInvite.remove();
await teamInvite.deleteOne();
throw new BadRequestError('Team does not exist anymore');
}

Expand All @@ -149,7 +149,7 @@ export async function removeInvite(request_id, id, admin) {
await verifyRequestedTeam(id, admin, ActionTypes.UPDATE);

const teamInvite = await getTeamInviteById(request_id);
return teamInvite.remove();
return teamInvite.deleteOne();
}

export async function addTeamMember(member, id, admin) {
Expand Down
1 change: 1 addition & 0 deletions tests/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ describe('Testing Environment status change', () => {

describe('Testing component association', () => {
beforeAll(async () => {
await setupDatabase();
await request(app)
.post('/component/create')
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
Expand Down