diff --git a/sci-log-db/src/__tests__/acceptance/logbook.controller.acceptance.ts b/sci-log-db/src/__tests__/acceptance/logbook.controller.acceptance.ts index 02d27f40..a730d487 100644 --- a/sci-log-db/src/__tests__/acceptance/logbook.controller.acceptance.ts +++ b/sci-log-db/src/__tests__/acceptance/logbook.controller.acceptance.ts @@ -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')); + }); }); diff --git a/sci-log-db/src/controllers/image.controller.ts b/sci-log-db/src/controllers/image.controller.ts index 4dd15521..163eb12a 100644 --- a/sci-log-db/src/controllers/image.controller.ts +++ b/sci-log-db/src/controllers/image.controller.ts @@ -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( diff --git a/sci-log-db/src/mixins/basesnippet.repository-mixin.ts b/sci-log-db/src/mixins/basesnippet.repository-mixin.ts index b3cf36d3..39563049 100644 --- a/sci-log-db/src/mixins/basesnippet.repository-mixin.ts +++ b/sci-log-db/src/mixins/basesnippet.repository-mixin.ts @@ -25,6 +25,8 @@ const fs = require('fs'); type ExpandedBasesnippet = Basesnippet & { ownerGroup: string; accessGroups: string[]; + thumbnail?: string; + thumbnailHash: string; }; function UpdateAndDeleteRepositoryMixin< @@ -59,6 +61,14 @@ function UpdateAndDeleteRepositoryMixin< ): Promise { 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, diff --git a/sci-log-db/src/models/logbook.model.ts b/sci-log-db/src/models/logbook.model.ts index 076dfb45..024a3bd5 100644 --- a/sci-log-db/src/models/logbook.model.ts +++ b/sci-log-db/src/models/logbook.model.ts @@ -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,