Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVE] Allow apps to update persistence by association #12681

Merged
merged 1 commit into from
Nov 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/rocketchat-apps/server/bridges/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,19 @@ export class AppPersistenceBridge {

throw new Error('Not implemented.');
}

async updateByAssociation(association, data, upsert, appId) {
console.log(`The App ${ appId } is updating the record with association to data as follows:`, association, data);

if (typeof data !== 'object') {
throw new Error('Attempted to store an invalid data type, it must be an object.');
}

const query = {
appId,
associations: association,
};

return this.orch.getPersistenceModel().upsert(query, { $set: { data } }, { upsert });
}
}