Add company-scoped delivery store on manifest
This commit is contained in:
25
src/store/delivery/delete.js
Normal file
25
src/store/delivery/delete.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { DELETE_MANIFEST, DELIVERY_TYPE } from '../../sql/delivery.js';
|
||||
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
|
||||
|
||||
export default function del(pool) {
|
||||
const access = resolveCompanyAccess(pool);
|
||||
|
||||
return async (googleAuthId, companyId, id) => {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error('Delivery not found');
|
||||
}
|
||||
|
||||
await access(googleAuthId, companyId);
|
||||
|
||||
const result = await pool
|
||||
.request()
|
||||
.input('id', id)
|
||||
.input('companyId', companyId)
|
||||
.input('type', DELIVERY_TYPE)
|
||||
.query(DELETE_MANIFEST);
|
||||
|
||||
if (!result.rowsAffected[0]) {
|
||||
throw new Error('Delivery not found');
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user