mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat: add s3 env variables to .env.example
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
import { DeleteObjectCommand } from '@aws-sdk/client-s3';
|
||||
import { s3 } from '@/lib/S3/S3';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { s3 } from '@/lib/S3/S3';
|
||||
import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import config from '@/config';
|
||||
import UnitOfWork from '../UnitOfWork';
|
||||
import { Knex } from 'knex';
|
||||
|
||||
@Service()
|
||||
export class DeleteAttachment {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private uow: UnitOfWork;
|
||||
|
||||
/**
|
||||
* Deletes the give file attachment file key.
|
||||
* @param {number} tenantId
|
||||
@@ -17,7 +23,7 @@ export class DeleteAttachment {
|
||||
const { Document, DocumentLink } = this.tenancy.models(tenantId);
|
||||
|
||||
const params = {
|
||||
Bucket: process.env.AWS_BUCKET,
|
||||
Bucket: config.s3.bucket,
|
||||
Key: filekey,
|
||||
};
|
||||
await s3.send(new DeleteObjectCommand(params));
|
||||
@@ -26,10 +32,14 @@ export class DeleteAttachment {
|
||||
.findOne('key', filekey)
|
||||
.throwIfNotFound();
|
||||
|
||||
// Delete all document links
|
||||
await DocumentLink.query().where('documentId', foundDocument.id).delete();
|
||||
await this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
// Delete all document links
|
||||
await DocumentLink.query(trx)
|
||||
.where('documentId', foundDocument.id)
|
||||
.delete();
|
||||
|
||||
// Delete thedocument.
|
||||
await Document.query().findById(foundDocument.id).delete();
|
||||
// Delete thedocument.
|
||||
await Document.query(trx).findById(foundDocument.id).delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user