feat: add socker connection between client and server

This commit is contained in:
Ahmed Bouhuolia
2024-02-24 00:18:48 +02:00
parent 1fd8a53ed1
commit 2d3544fe37
16 changed files with 357 additions and 27 deletions

View File

@@ -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();
};