Skip to content

Commit

Permalink
Add thumbnailHash when updating logbook
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Feb 1, 2024
1 parent 0d16867 commit 8fa50d8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
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

0 comments on commit 8fa50d8

Please sign in to comment.