mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat: add socker connection between client and server
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { SystemPlaidItem, Tenant } from '@/system/models';
|
||||
import tenantDependencyInjection from '@/api/middleware/TenantDependencyInjection';
|
||||
|
||||
export const PlaidWebhookTenantBootMiddleware = async (
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => {
|
||||
const { item_id: plaidItemId } = req.body;
|
||||
const plaidItem = await SystemPlaidItem.query().findOne({ plaidItemId });
|
||||
|
||||
const notFoundOrganization = () => {
|
||||
return res.boom.unauthorized('Organization identication not found.', {
|
||||
errors: [{ type: 'ORGANIZATION.ID.NOT.FOUND', code: 100 }],
|
||||
});
|
||||
};
|
||||
// In case the given organization not found.
|
||||
if (!plaidItem) {
|
||||
return notFoundOrganization();
|
||||
}
|
||||
const tenant = await Tenant.query()
|
||||
.findById(plaidItem.tenantId)
|
||||
.withGraphFetched('metadata');
|
||||
|
||||
// When the given organization id not found on the system storage.
|
||||
if (!tenant) {
|
||||
return notFoundOrganization();
|
||||
}
|
||||
tenantDependencyInjection(req, tenant);
|
||||
next();
|
||||
};
|
||||
Reference in New Issue
Block a user