forked from er-santosh/bigcapital
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/get-tenant-of-authenticated-user
Tasks done --- - Created api endpoint to fetch authenticated user details and its tenant. - Added cors middleware to allow resources to whitelisted domains.
- Loading branch information
1 parent
16323e9
commit be546b2
Showing
12 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import cors from 'cors'; | ||
import config from '@/config'; | ||
|
||
const corsMiddleware = cors({ | ||
origin: function (origin, callback) { | ||
const allowedDomains = config.cors.whitelistedDomains; | ||
|
||
const requestOrigin = origin?.endsWith('/') ? origin?.slice(0, -1) : origin; | ||
|
||
if (allowedDomains.indexOf(requestOrigin) !== -1 || !requestOrigin) { | ||
callback(null, true); | ||
} else { | ||
callback(new Error('Not allowed by CORS')); | ||
} | ||
}, | ||
}); | ||
|
||
export default corsMiddleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Inject, Service } from 'typedi'; | ||
import { ITenant } from '@/interfaces'; | ||
import { TenantService } from '@/services/Tenancy/TenantService'; | ||
|
||
@Service() | ||
export class GetAuthMe { | ||
@Inject() | ||
private tenantService: TenantService; | ||
|
||
/** | ||
* Retrieves the authenticated tenant. | ||
* @param {number} tenantId | ||
* @returns {Promise<ITenant>} | ||
*/ | ||
public async getAuthTenant(tenantId: number): Promise<ITenant> { | ||
const tenant = await this.tenantService.getTenantById(tenantId); | ||
|
||
return tenant; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Service } from 'typedi'; | ||
import { Tenant } from '@/system/models'; | ||
import ModelEntityNotFound from '@/exceptions/ModelEntityNotFound'; | ||
|
||
@Service() | ||
export class TenantService { | ||
/** | ||
* Retrieves tenant by id. | ||
* @param {number} tenantId | ||
* @returns {Promise<any>} | ||
*/ | ||
public async getTenantById(tenantId: number): Promise<any> { | ||
const tenant = await Tenant.query() | ||
.findById(tenantId) | ||
.withGraphFetched('metadata'); | ||
|
||
if (!tenant) throw new ModelEntityNotFound(tenantId); | ||
|
||
return tenant; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.