fix: invite user to the system.

fix: soft delete system user.
This commit is contained in:
a.bouhuolia
2021-01-19 13:18:48 +02:00
parent ef53b25c18
commit 59f44d9ef6
17 changed files with 320 additions and 136 deletions

View File

@@ -14,7 +14,6 @@ const attachCurrentUser = async (req: Request, res: Response, next: Function) =>
try {
Logger.info('[attach_user_middleware] finding system user by id.');
const user = await systemUserRepository.findOneById(req.token.id);
console.log(user);
if (!user) {
Logger.info('[attach_user_middleware] the system user not found.');

View File

@@ -9,11 +9,13 @@ export default (req: Request, res: Response, next: Function) => {
throw new Error('Should load this middleware after `TenancyMiddleware`.');
}
if (!req.tenant.seededAt) {
Logger.info('[ensure_tenant_initialized_middleware] tenant databae not seeded.');
Logger.info(
'[ensure_tenant_initialized_middleware] tenant databae not seeded.'
);
return res.boom.badRequest(
'Tenant database is not seeded with initial data yet.',
{ errors: [{ type: 'TENANT.DATABASE.NOT.SEED' }] },
{ errors: [{ type: 'TENANT.DATABASE.NOT.SEED' }] }
);
}
next();
};
};

View File

@@ -1,7 +1,11 @@
import { Request, Response, NextFunction } from 'express';
import { Container } from 'typedi';
export default (subscriptionSlug = 'main') => async (req: Request, res: Response, next: NextFunction) => {
export default (subscriptionSlug = 'main') => async (
req: Request,
res: Response,
next: NextFunction
) => {
const { tenant, tenantId } = req;
const Logger = Container.get('logger');
const { subscriptionRepository } = Container.get('repositories');
@@ -10,22 +14,28 @@ export default (subscriptionSlug = 'main') => async (req: Request, res: Response
throw new Error('Should load `TenancyMiddlware` before this middleware.');
}
Logger.info('[subscription_middleware] trying get tenant main subscription.');
const subscription = await subscriptionRepository.getBySlugInTenant(subscriptionSlug, tenantId);
const subscription = await subscriptionRepository.getBySlugInTenant(
subscriptionSlug,
tenantId
);
// Validate in case there is no any already subscription.
if (!subscription) {
Logger.info('[subscription_middleware] tenant has no subscription.', { tenantId });
return res.boom.badRequest(
'Tenant has no subscription.',
{ errors: [{ type: 'TENANT.HAS.NO.SUBSCRIPTION' }] }
);
Logger.info('[subscription_middleware] tenant has no subscription.', {
tenantId,
});
return res.boom.badRequest('Tenant has no subscription.', {
errors: [{ type: 'TENANT.HAS.NO.SUBSCRIPTION' }],
});
}
// Validate in case the subscription is inactive.
else if (subscription.inactive()) {
Logger.info('[subscription_middleware] tenant main subscription is expired.', { tenantId });
Logger.info(
'[subscription_middleware] tenant main subscription is expired.',
{ tenantId }
);
return res.boom.badRequest(null, {
errors: [{ type: 'ORGANIZATION.SUBSCRIPTION.INACTIVE' }],
});
}
next();
};
};

View File

@@ -1,5 +1,3 @@
import logger from "src/loaders/logger";
import { Request, Response, NextFunction } from 'express';
import { Container } from 'typedi';