Skip to content

Commit

Permalink
Use modern syntax for adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Jun 18, 2024
1 parent e6d33ea commit caea7d0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
15 changes: 6 additions & 9 deletions frontend/app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import JSONAPIAdapter from "@ember-data/adapter/json-api";
import { computed } from "@ember/object";
import { pluralize } from "ember-inflector";
import { underscore } from "@ember/string";
import ENV from "../config/environment";

export default JSONAPIAdapter.extend({
namespace: "api",
export default class ApplicationAdapter extends JSONAPIAdapter {
namespace = "api";

pathForType(type) {
return pluralize(underscore(type));
},
}

headers: computed(function () {
/* eslint-disable no-undef */
get headers() {
return {
"X-CSRF-Token": ENV.CSRFToken,
"content-type": "application/json"
};
/* eslint-enable no-undef */
})
});
}
}
4 changes: 2 additions & 2 deletions frontend/app/adapters/encryptable-credential.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ApplicationAdapter from "./application";

export default ApplicationAdapter.extend({
export default class EncryptableCredentialAdapter extends ApplicationAdapter{
pathForType() {
return "encryptables";
}
});
};
4 changes: 2 additions & 2 deletions frontend/app/adapters/encryptable-file.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ApplicationAdapter from "./application";

export default ApplicationAdapter.extend({
export default class EncryptableFileAdapter extends ApplicationAdapter{
pathForType() {
return "encryptables";
}
});
};
18 changes: 9 additions & 9 deletions frontend/app/adapters/folder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ApplicationAdapter from "./application";

export default ApplicationAdapter.extend({
namespace: "api/teams",
export default class FolderAdapter extends ApplicationAdapter {
namespace = "api/teams";

urlForQuery(query, modelName) {
if (query.teamId) {
Expand All @@ -11,7 +11,7 @@ export default ApplicationAdapter.extend({
return url;
}
return super.urlForQuery(query, modelName);
},
}

urlForQueryRecord(query, modelName) {
if (query.teamId) {
Expand All @@ -22,27 +22,27 @@ export default ApplicationAdapter.extend({
return url;
}
return super.urlForQueryRecord(query, modelName);
},
}

urlForCreateRecord(modelName, snapshot) {
return `/${this.namespace}/${snapshot.belongsTo("team", {
id: true
})}/${this.pathForType()}`;
},
}

urlForUpdateRecord(id, modelName, snapshot) {
return `/${this.namespace}/${snapshot.belongsTo("team", {
id: true
})}/${this.pathForType()}/${id}`;
},
}

urlForDeleteRecord(id, modelName, snapshot) {
return `/${this.namespace}/${snapshot.belongsTo("team", {
id: true
})}/${this.pathForType()}/${id}`;
},
}

pathForType: function () {
pathForType() {
return "folders";
}
});
}
6 changes: 3 additions & 3 deletions frontend/app/adapters/team-api-user.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ApplicationAdapter from "./application";
import { pluralize } from "ember-inflector";

export default ApplicationAdapter.extend({
export default class TeamApiUserAdapter extends ApplicationAdapter {
pathForType(modelName) {
let snakeCased = modelName.replace("-", "_");
return pluralize(snakeCased);
},
}

urlForQuery(query, modelName) {
let teamId = query.teamId;
Expand All @@ -15,4 +15,4 @@ export default ApplicationAdapter.extend({
}
return super.urlForQuery(query, modelName);
}
});
}
12 changes: 6 additions & 6 deletions frontend/app/adapters/teammember.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ApplicationAdapter from "./application";

export default ApplicationAdapter.extend({
namespace: "api/teams",
export default class TeammemberAdapter extends ApplicationAdapter {
namespace = "api/teams";

urlForQuery(query, modelName) {
if (query.teamId) {
Expand All @@ -18,21 +18,21 @@ export default ApplicationAdapter.extend({
return url;
}
return super.urlForQuery(query, modelName);
},
}

pathForType() {
return "members";
},
}

urlForCreateRecord(modelName, snapshot) {
return `/${this.namespace}/${snapshot.belongsTo("team", {
id: true
})}/${this.pathForType()}`;
},
}

urlForDeleteRecord(id, modelName, snapshot) {
return `/${this.namespace}/${snapshot.belongsTo("team", {
id: true
})}/${this.pathForType()}/${id}`;
}
});
}

0 comments on commit caea7d0

Please sign in to comment.