-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SIMSBIOHUB-606: Upload Capture Attachments (#1388)
- Upload capture attachments - Upload capture attachments and remove during edit - Download attachments
- Loading branch information
Showing
33 changed files
with
2,281 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { z } from 'zod'; | ||
/** | ||
* Note: These files should only contain the `Data Models` and `Data Records` with equivalent inferred types. | ||
* | ||
* Data Models contain a 1 to 1 mapping of the database table. | ||
* | ||
* Data Records contain a 1 to 1 mapping of the database table, minus the audit columns. | ||
*/ | ||
|
||
/** | ||
* Critter Capture Attachment Model. | ||
* | ||
* @description Data model for `critter_capture_attachment`. | ||
*/ | ||
export const CritterCaptureAttachmentModel = z.object({ | ||
critter_capture_attachment_id: z.number(), | ||
uuid: z.string().nullable(), | ||
critter_id: z.number(), | ||
critterbase_capture_id: z.string(), | ||
file_type: z.string(), | ||
file_name: z.string().nullable(), | ||
file_size: z.number().nullable(), | ||
title: z.string().nullable(), | ||
description: z.string().nullable(), | ||
key: z.string(), | ||
create_date: z.string(), | ||
create_user: z.number(), | ||
update_date: z.string().nullable(), | ||
update_user: z.number().nullable(), | ||
revision_count: z.number() | ||
}); | ||
|
||
export type CritterCaptureAttachmentModel = z.infer<typeof CritterCaptureAttachmentModel>; | ||
|
||
/** | ||
* Critter Capture Attachment Record. | ||
* | ||
* @description Data record for `critter_capture_attachment`. | ||
*/ | ||
export const CritterCaptureAttachmentRecord = CritterCaptureAttachmentModel.omit({ | ||
create_date: true, | ||
create_user: true, | ||
update_date: true, | ||
update_user: true, | ||
revision_count: true | ||
}); | ||
|
||
export type CritterCaptureAttachmentRecord = z.infer<typeof CritterCaptureAttachmentRecord>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { z } from 'zod'; | ||
/** | ||
* Note: These files should only contain the `Data Models` and `Data Records` with equivalent inferred types. | ||
* | ||
* Data Models contain a 1 to 1 mapping of the database table. | ||
* | ||
* Data Records contain a 1 to 1 mapping of the database table, minus the audit columns. | ||
*/ | ||
|
||
/** | ||
* Critter Mortality Attachment Model. | ||
* | ||
* @description Data model for `critter_mortality_attachment`. | ||
*/ | ||
export const CritterMortalityAttachmentModel = z.object({ | ||
critter_mortality_attachment_id: z.number(), | ||
uuid: z.string().nullable(), | ||
critter_id: z.string(), | ||
critterbase_mortality_id: z.string(), | ||
file_type: z.string(), | ||
file_name: z.string().nullable(), | ||
file_size: z.number().nullable(), | ||
title: z.string().nullable(), | ||
description: z.string().nullable(), | ||
key: z.string(), | ||
create_date: z.string(), | ||
create_user: z.number(), | ||
update_date: z.string().nullable(), | ||
update_user: z.number().nullable(), | ||
revision_count: z.number() | ||
}); | ||
|
||
export type CritterMortalityAttachmentModel = z.infer<typeof CritterMortalityAttachmentModel>; | ||
|
||
/** | ||
* Critter Mortality Attachment Record. | ||
* | ||
* @description Data record for `critter_mortality_attachment`. | ||
*/ | ||
export const CritterMortalityAttachmentRecord = CritterMortalityAttachmentModel.omit({ | ||
create_date: true, | ||
create_user: true, | ||
update_date: true, | ||
update_user: true, | ||
revision_count: true | ||
}); | ||
|
||
export type CritterMortalityAttachmentRecord = z.infer<typeof CritterMortalityAttachmentRecord>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...{surveyId}/critters/{critterId}/captures/{critterbaseCaptureId}/attachments/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { deleteCritterCaptureAttachments } from '.'; | ||
import * as db from '../../../../../../../../../../database/db'; | ||
import { CritterAttachmentService } from '../../../../../../../../../../services/critter-attachment-service'; | ||
import * as S3 from '../../../../../../../../../../utils/file-utils'; | ||
import { getMockDBConnection, getRequestHandlerMocks } from '../../../../../../../../../../__mocks__/db'; | ||
|
||
describe('deleteCritterCaptureAttachments', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('deletes all attachments for a critter capture', async () => { | ||
const mockDBConnection = getMockDBConnection({ | ||
open: sinon.stub(), | ||
commit: sinon.stub(), | ||
release: sinon.stub(), | ||
rollback: sinon.stub() | ||
}); | ||
|
||
const getDBConnectionStub = sinon.stub(db, 'getDBConnection').returns(mockDBConnection); | ||
const mockFindAttachments = sinon.stub(CritterAttachmentService.prototype, 'findAllCritterCaptureAttachments'); | ||
const mockDeleteAttachments = sinon.stub(CritterAttachmentService.prototype, 'deleteCritterCaptureAttachments'); | ||
const mockBulkDeleteFilesFromS3 = sinon.stub(S3, 'bulkDeleteFilesFromS3'); | ||
|
||
mockFindAttachments.resolves([{ critter_capture_attachment_id: 1, key: 'DELETE_S3_KEY' }] as any[]); | ||
mockDeleteAttachments.resolves(['DELETE_S3_KEY']); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
|
||
mockReq.params = { | ||
projectId: '1', | ||
surveyId: '2', | ||
critterId: '3', | ||
critterbaseCaptureId: '123e4567-e89b-12d3-a456-426614174000' | ||
}; | ||
|
||
const requestHandler = deleteCritterCaptureAttachments(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
expect(getDBConnectionStub).to.have.been.calledOnce; | ||
expect(mockDBConnection.open).to.have.been.calledOnce; | ||
|
||
expect(mockFindAttachments).to.have.been.calledOnceWithExactly(2, '123e4567-e89b-12d3-a456-426614174000'); | ||
expect(mockDeleteAttachments).to.have.been.calledOnceWithExactly(2, [1]); | ||
|
||
expect(mockBulkDeleteFilesFromS3).to.have.been.calledOnceWithExactly(['DELETE_S3_KEY']); | ||
|
||
expect(mockRes.status).to.have.been.calledWith(200); | ||
expect(mockRes.send).to.have.been.calledWith(); | ||
|
||
expect(mockDBConnection.commit).to.have.been.calledOnce; | ||
expect(mockDBConnection.release).to.have.been.calledOnce; | ||
expect(mockDBConnection.rollback).to.not.have.been.called; | ||
}); | ||
}); |
Oops, something went wrong.