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

Add thumbnailHash when updating logbook #324

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,25 @@ describe('Logbook', function (this: Suite) {
throw err;
});
});

it('add thumbnail hash when editing logbook', async () => {
const file = await client
.post(`/filesnippet`)
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.send({accessHash: 'hash', readACL: [logbookSnippet.ownerGroup]})
.expect(200);
await client
.patch(`/logbooks/${logbookSnippetId}`)
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.send({thumbnail: file.body.id})
.expect(204);
await client
.get(`/logbooks/${logbookSnippetId}`)
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.expect(200)
.then(result => expect(result.body.thumbnailHash).to.eql('hash'));
});
});
2 changes: 1 addition & 1 deletion sci-log-db/src/controllers/image.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ImageController {
}
const data = dataQuery[0];
console.log(data);
if (typeof data._fileId == 'undefined') {
if (typeof data?._fileId == 'undefined') {
throw new HttpErrors.BadRequest(`Retrieving sandbox data is deprecated.`);
}
const bucket = new Mongo.GridFSBucket(
Expand Down
10 changes: 10 additions & 0 deletions sci-log-db/src/mixins/basesnippet.repository-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const fs = require('fs');
type ExpandedBasesnippet = Basesnippet & {
ownerGroup: string;
accessGroups: string[];
thumbnail?: string;
thumbnailHash: string;
};

function UpdateAndDeleteRepositoryMixin<
Expand Down Expand Up @@ -59,6 +61,14 @@ function UpdateAndDeleteRepositoryMixin<
): Promise<void> {
const baseSnippetRepository = await this.baseSnippetRepository();
const snippet = await baseSnippetRepository.findById(id, {}, options);
if (basesnippet.thumbnail && !basesnippet.thumbnailHash)
basesnippet.thumbnailHash = (
await baseSnippetRepository.findById(
basesnippet.thumbnail,
{},
options,
)
).accessHash;
const patches = await this.applyFromOwnerAccessAndGetChanged(
basesnippet,
snippet,
Expand Down
6 changes: 6 additions & 0 deletions sci-log-db/src/models/logbook.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export class Logbook extends Basesnippet {
})
thumbnail?: string;

@property({
type: 'string',
description: 'Optional hash of the image/logo associated to this logbook',
})
thumbnailHash?: string;

@property({
type: 'string',
required: true,
Expand Down
Loading