Skip to content

Feat/829 pdf backend #937

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Feat/829 pdf backend #937

wants to merge 21 commits into from

Conversation

fbarreta
Copy link
Contributor

@fbarreta fbarreta commented Jun 17, 2025

Controller, services + dam API interaction to list, create, update and delete PDF resources.

@fbarreta fbarreta self-assigned this Jun 17, 2025
@fbarreta fbarreta force-pushed the feat/829-pdf-backend branch from 13d5df7 to 6cd5d2e Compare June 18, 2025 00:00
@jimmypalelil
Copy link
Contributor

jimmypalelil commented Jun 19, 2025

@fbarreta

I took a look at your PR. I know its a WIP but just a few things I noticed:

  • Good call on creating a new module for the resource-docs. this can be a sub-module for recreation-resource. the endpoint paths will be automatically picked up as the nested route.
  • Need Auth checks. There are decorators and role guards already created. we only need rst-viewer role to be checked for the first pass. You can use my branch as an example.
  • When registering MulterModule with MulterModule.register() we don’t need diskStorage we can just use memoryStorage.

lemme know what you think

@@ -16,6 +17,7 @@ import { RecreationResourceModule } from "@/recreation-resource/recreation-resou
AuthModule,
TerminusModule,
RecreationResourceModule,
ResourceDocsModule,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be better to have this imported under RecreationResourceModule

declare const window: any;
const NodeFormData =
// eslint-disable-next-line @typescript-eslint/no-require-imports
typeof window === "undefined" ? require("form-data") : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for? window will always be undefined right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a technique used to test, because running vitest with form data we can instantiate while testing.

description: "Doc title",
example: "Campbell river site map",
})
@IsNotEmpty()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shoud we add length and regex constraints here?

@Get(":rec_resource_id/docs/:ref_id")
@ApiOperation({
summary: "Get one document resource by reference ID",
operationId: "getDocumentResourceById",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we name it getDocumentByResourceId to be consistent with the one above?

})
@ApiResponse({
status: 404,
description: "Recreation Resource document not found",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

should be "Recreation Resource not found"

}
if (file) {
if (!allowedTypes.includes(file.mimetype)) {
throw new HttpException("File Type not allowed", 501);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 501 appropriate here. isnt this a user error

await uploadFile(ref_id, file);
const files = await getResourcePath(ref_id);
url = this.getOriginalFilePath(files);
docToUpdate["url"] = url;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you update the original, do all the other image variants keep the same url?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was actually a good insight ! I assumed that changing the file, the URL would change ... but that was not the case.

url = this.getOriginalFilePath(files);
docToUpdate["url"] = url;
}
const result = await this.prisma.$transaction([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transaction is not necessary here

if (resource === null) {
throw new HttpException("Recreation Resource not found", 404);
}
const ref_id = await createResource();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these dam api are called one after the other. if anyone of them fails, will it emit logs that show which one has failed?

async getById(
rec_resource_id: string,
ref_id: string,
): Promise<RecreationResourceDocDto | null> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this ever return null?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants