Appearance
SharedBrandsToOrganizationsModule
The SharedBrandsToOrganizationsModule enables users to share brands with other organizations. This API facilitates seamless collaboration and resource sharing between organizations, ensuring that users from different organizations have access to the brands they are authorized to use. By utilizing this API, organizations can effectively manage user access and permissions for shared brands, streamlining brand-related operations and promoting cross-organizational cooperation.
Entity Inheritance
NestKit provide base classes that can be inherited and customized with your needs. For entities we use TypeORM TableInheritance.
Key Components
The module provides a set of reusable components that can be easily integrated into a NestJS project:
SharedBrandToOrganization Entity
The SharedBrandToOrganization entity represents the relationship between a shared brand and an organization. This entity stores essential information such as the brand ID, organization ID, access levels, and any additional legal notices. By managing these associations, the SharedBrandToOrganization entity enables efficient sharing of brands across organizations while maintaining proper access control and permissions for users in each organization.
SharedBrandToOrganizationsService
The SharedBrandsToOrganizationsService is responsible for managing the sharing of brands across different organizations. This service provides essential methods for creating, updating, and deleting associations between brands and organizations.
SharedBrandToOrganizationsResolver
The SharedBrandsToOrganizationsResolver handles GraphQL queries and mutations related to sharing brands with organizations.
How to install SharedBrandToOrganizationModule to my app
To create a SharedBrandToOrganizationModule in NestJS, you can follow these steps:
Create a
shared-brands-to-organizationsfolder in your project'ssrc/modulesdirectory.Install the required dependencies for
SharedBrandToOrganizationModule:Inside the
shared-brands-to-organizationsfolder, create ashared-brands-to-organization.entity.tsfile and extendsSharedBrandToOrganizationfrom NestKit with the following code:ts// src/modules/shared-brands-to-organizations/shared-brands-to-organization.entity.ts import { MaybeNull } from '@deeepvision/nest-kit'; import { Field, ObjectType } from '@nestjs/graphql'; import { ChildEntity } from 'typeorm'; import { Brand } from '../brands/brand.entity'; import { Organization } from '../organizations/organization.entity'; import { User } from '../users/user.entity'; import { BaseSharedBrandToOrganization } from '@deeepvision/nest-kit/dist/modules/shared-brands-to-organizations'; @ObjectType() @ChildEntity() export class SharedBrandToOrganization extends BaseSharedBrandToOrganization { @Field(() => Brand) brand!: Promise<Brand>; @Field(() => Organization) organization!: Promise<Organization>; @Field(() => User) sharedBy!: Promise<MaybeNull<User>>; }Inside the
shared-brands-to-organizationsfolder, create ashared-brands-to-organizations.service.tsfile and extendsSharedBrandToOrganizationsServicefrom NestKit with the following code:ts// src/modules/shared-brands-to-organizations/shared-brands-to-organizations.service.ts import { BaseSharedBrandsToOrganizationsService } from '@deeepvision/nest-kit/dist/modules/shared-brands-to-organizations'; import { SharedBrandToOrganization } from './shared-brand-to-organization.entity'; export class SharedBrandsToOrganizationsService extends BaseSharedBrandsToOrganizationsService<SharedBrandToOrganization> {}Inside the
shared-brands-to-organizationsfolder, create ashared-brands-to-organizations.resolver.tsfile and extendsBaseSharedBrandsToOrganizationsResolverwith the following code:ts// src/modules/shared-brands-to-organizations/shared-brands-to-organizations.resolver.ts import { BaseSharedBrandsToOrganizationsResolver } from '@deeepvision/nest-kit/dist/modules/shared-brands-to-organizations'; import { Resolver } from '@nestjs/graphql'; import { SharedBrandToOrganization } from './shared-brand-to-organization.entity'; @Resolver(() => SharedBrandToOrganization) export class SharedBrandsToOrganizationsResolver extends BaseSharedBrandsToOrganizationsResolver(SharedBrandToOrganization) {}Inside the
shared-brands-to-organizationsfolder, create ashared-brands-to-organizations.module.tsfile with the following code:ts// src/modules/shared-brands-to-organizations/shared-brands-to-organizations.module.ts import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { SharedBrandToOrganization } from './shared-brand-to-organization.entity'; import { SharedBrandsToOrganizationsResolver } from './shared-brand-to-organizations.resolver'; import { SharedBrandsToOrganizationsService } from './shared-brand-to-organizations.service'; import { SHARED_BRANDS_TO_ORGANIZATIONS_SERVICE_TOKEN } from '@deeepvision/nest-kit/dist/modules/shared-brands-to-organizations'; @Module({ imports: [ TypeOrmModule.forFeature([SharedBrandToOrganization]), ], providers: [ SharedBrandsToOrganizationsService, { provide: SHARED_BRANDS_TO_ORGANIZATIONS_SERVICE_TOKEN, useExisting: SharedBrandsToOrganizationsService, }, SharedBrandsToOrganizationsResolver, ], exports: [ SharedBrandsToOrganizationsService, { provide: SHARED_BRANDS_TO_ORGANIZATIONS_SERVICE_TOKEN, useExisting: SharedBrandsToOrganizationsService, }, ], }) export class SharedBrandsToOrganizationsModule {}Finally, import the
SharedBrandsToOrganizationsModuleinto your mainAppModuleor another module:ts// src/modules/app.module.ts import { Module } from '@nestjs/common'; import { SharedBrandsToOrganizationsModule } from './modules/shared-brands-to-organizations/shared-brands-to-organizations.module.ts'; @Module({ imports: [SharedBrandsToOrganizationsModule], }) export class AppModule {}
In this code, we are importing the SharedBrandsToOrganizationsModule and adding it to the imports array of our AppModule.
How to share brand with organization
Here's an example of how to call SharedBrandsToOrganizationsService.create with an object literal based on CreateSharedBrandToOrganizationOptions:
ts
const sbToOrg = await this.sharedBrandsToOrganizationsService.create({
brandId: 'hcb:xxxxxxxxxxx',
organizationId: 'hcorg:xxxxxxxxxxx',
accessLevels: ['brand:view'],
legalNotice: { // RichText
tiptap: {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This brand is shared with your organization for viewing and editing purposes only. Any unauthorized use is prohibited.'
}
]
}
]
}
}
});In this example, a brand with ID hcb:xxxxxxxxxxx is being shared with an organization with ID hcorg:xxxxxxxxxxx. The provided access level brand:view, allowing the organization to view the shared brand. A legal notice is also included as a part of the sharing process.
Share brand with organization with GraphQL
Here's an example GraphQL mutation to share brand with organization
How to get brand sharing by ID
Use the getOne() method from your SharedBrandsToOrganizationsService to get a sharing by id in other parts of your application.
ts
const sbToOrg = await this.sharedBrandsToOrganizationsService.getOne('sborg:xxxxxxxxxxx');Use the getOneOrFail() method to retrieve a sharing by id or throw an error if not found.
ts
const sbToOrg = await this.sharedBrandsToOrganizationsService.getOneOrFail('sborg:xxxxxxxxxxx', ctx);
const organization = await sbToOrg.organization;
const brand = await sbToOrg.brand;
console.log(`Brand "${brand.id}" was shared to organization with id "${organization.id}" `)Fetch brand to organization sharing by id with GraphQL
Here's an example GraphQL query to fetch sharing by id.
How to get brand to organization sharings list
Use the getMany() method in other parts of your application to retrieve a list of brands sharings to organizations.
ts
const [sharedBrandsToOrganizations, meta] = await this.sharedBrandsToOrganizationsService.getMany({
filter: {
...
},
orderBy: SharedBrandsToOrganizationsOrderBy.createdAt_ASC,
});See SharedBrandsToOrganizationsOrderBy and SharedBrandsToOrganizationsFilter for more information on how to filter and order user roles.
Fetch brand to organization sharings list with GraphQL
Here's an example GraphQL query to fetch sharings.
How to delete brand to organization sharing
Call the delete method of the sharedBrandsToOrganizationsService and pass in the id of the sharing you want to delete:
ts
await this.sharedBrandsToOrganizationsService.delete('sborg:xxxxxxxxxxx');In this example, we are deleting a sharing with an id of sborg:xxxxxxxxxxx.
Delete brand to organization sharing with GraphQL
Here's an example GraphQL mutation to delete brand to organization sharing.