* feat: 🎸 Add worker serializer Add worker serializer that focus' on `config_tags.type` and `canonical_tags.type`. [API](https://docs.google.com/document/d/1G-lfl8gk9NfoKFImSpHb90E3xC3CSEVDwVy3bJ9eOhA/edit#heading=h.9e06o4b8etpi) ✅ Closes: ICU-5241 * refactor: 💡 refactored `models/worker.js` Because `canonical_tags` and `config_tags` are `readOnly` attributes, we could use `attr` decorator instead of `fragment`. ✅ Closes: ICU-5241 * refactored `model/worker.js and deleted un-needed files * refactor: 💡 Refactored model/worker.js and created test Refactored model/worker.js to include custom method for POST route for adding new worker. BREAKING CHANGE: 🧨 no ✅ Closes: ICU-5241 * refactor: 💡 Refactored custom POST route method for worker Refactored custom method on `model/worker.js` to include serialization for `worker_genrated_auth_token` BREAKING CHANGE: 🧨 no ✅ Closes: ICU-5241 * refactor: 💡 Refactor test Refactor model/worker-test.js and serializers/worker.js BREAKING CHANGE: 🧨 no ✅ Closes: ICU-5241 * Update addons/api/addon/serializers/worker.js Co-authored-by: Dharini Jeeva <dharini@hashicorp.com> * update worker.js documentation block Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
import ApplicationSerializer from './application';
|
|
|
|
export default class WorkerSerializer extends ApplicationSerializer {
|
|
// =methods
|
|
|
|
/**
|
|
* If `adapterOptions.workerGeneratedAuthToken` is set,
|
|
* then the payload is serialized via `serializedWithGeneratedToken`.
|
|
* @override
|
|
* @param {Snapshot} snapshot
|
|
* @return {object}
|
|
*/
|
|
serialize(snapshot) {
|
|
let serialized = super.serialize(...arguments);
|
|
const workerGeneratedAuthToken = snapshot?.adapterOptions?.workerGeneratedAuthToken;
|
|
if (workerGeneratedAuthToken)
|
|
serialized = this.serializeWithGeneratedToken(snapshot, workerGeneratedAuthToken);
|
|
return serialized;
|
|
}
|
|
|
|
/**
|
|
* Returns a payload with `worker_generated_auth_token` serialized.
|
|
* @param {Snapshot} snapshot
|
|
* @param {[string]} worker_generated_auth_token
|
|
* @return {object}
|
|
*/
|
|
serializeWithGeneratedToken(snapshot, workerGeneratedAuthToken) {
|
|
return {
|
|
version: snapshot.attr('version'),
|
|
worker_generated_auth_token: workerGeneratedAuthToken
|
|
};
|
|
}
|
|
}
|