in api/v1/src/accounts/dataManager.js [699:727]
async function reset(projectId, accountId) {
try {
console.log(`Reset called for accountId: ${accountId}`);
let account = await getAccount(projectId, accountId, 'user');
if (account) {
if (account.policies) {
// Reformat policies for saving.
// TODO: Re-factor so this isn't a mess
account.policies = account.policies.map(e => e.policyId);
}
if (account.marketplace && account.marketplace.length > 0) {
const accountNames = account.marketplace.map(e => e.accountName);
// Clear the associated accountNames
account.marketplace = [];
const procurementUtil = new CommerceProcurementUtil(projectId);
for (const name of accountNames) {
console.log(`Resetting account for name: ${name}`);
await procurementUtil.resetAccount(name);
}
// Save the updated account record
await createOrUpdateAccount(projectId, null, account);
}
}
return { success: true, code: 200 };
} catch (err) {
console.error(err);
return { success: false, code: 500, errors: ['Failed to reset account(s)'] };
}
}