Skip to content

Commit

Permalink
Updates add/remove project resource methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdaley committed Nov 7, 2023
1 parent 264f867 commit 9f84245
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion web/app/components/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "hermes/types/project-status";
import { assert } from "@ember/debug";
import FlashMessageService from "ember-cli-flash/services/flash-messages";
import ConfigService from "hermes/services/config";

interface ProjectIndexComponentSignature {
Args: {
Expand All @@ -26,6 +27,7 @@ interface ProjectIndexComponentSignature {

export default class ProjectIndexComponent extends Component<ProjectIndexComponentSignature> {
@service("fetch") declare fetchSvc: FetchService;
@service("config") declare configSvc: ConfigService;
@service declare flashMessages: FlashMessageService;

/**
Expand Down Expand Up @@ -158,11 +160,15 @@ export default class ProjectIndexComponent extends Component<ProjectIndexCompone
* Removes the resource from the correct array, then saves the project.
*/
@action protected deleteResource(doc: RelatedResource): void {
const cachedDocuments = this.hermesDocuments.slice();
const cachedLinks = this.externalLinks.slice();

if ("googleFileID" in doc) {
this.hermesDocuments.removeObject(doc);
} else {
this.externalLinks.removeObject(doc);
}
void this.saveRelatedResources.perform(cachedDocuments, cachedLinks);
}

/**
Expand Down Expand Up @@ -338,7 +344,7 @@ export default class ProjectIndexComponent extends Component<ProjectIndexCompone

try {
await this.fetchSvc.fetch(
`/api/v1/projects/${this.args.project.id}/related-resources`,
`/api/${this.configSvc.config.api_version}/projects/${this.args.project.id}/related-resources`,
{
method: "PUT",
body: JSON.stringify(this.formattedRelatedResources),
Expand Down
2 changes: 1 addition & 1 deletion web/mirage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export default function (mirageConfig) {
});

// Fetch a project's related resources
this.put("/projects/:project_id", (schema, request) => {
this.put("/projects/:project_id/related-resources", (schema, request) => {
let project = schema.projects.findBy({
id: request.params.project_id,
});
Expand Down

0 comments on commit 9f84245

Please sign in to comment.