Skip to content

Commit

Permalink
Release: In-app Notifications, VC (#4789)
Browse files Browse the repository at this point in the history
* wip

* moved dir to adapters

* poc wingback create customer

* poc wingback create customer

* getEntitlements

* comment added

* first pass at two new modules for TemplatesManager, TemplateDefault

* added templates manager to space; removed the SpaceDefaults entity (module still present until move all data to be via defaults

* added templatesManager to platform

* moved creating of default innovatin flow input to space defaults

* back out space type on Template; tidy up Template module to use switch statements

* created template applier module

* tidy up naming

* updated set of default template types

* fixed circular dependency; moved logic for creating collaboration input to space defaults

* removed loading of defaults from files for collaboration content

* removed code based addition of callouts, innovation flow states

* tidy up naming

* added loading of default templates at platform level in to bootstrap

* removed option to create new innovation flow template

* added in migration:

* loading in templates on bootstrap

* added field for collaboration templates on templatesSet; added lookup for templatesManager

* added mutation to create template from collaboration; added logic to prevent template used as default to be deleted; fixed removal of template set on template manager

* initial creation of license + entitlements modules

* add license into account

* updated account to have license service + use that in mutations checking limits, removing notion of soft limits

* ensure data is loaded properly on account for license checking

* added mutation to reset the license calculations on account, including new auth privilege to be able to do so

* renamed Licensing module to LicensingFramework module; trigger license reset on Account after assigning / removing license

* removed usage of LicenseEngine outside of license services on space or account

* renamed entitlement to licenseEntitlement as entity; first pass at migration

* fixed issues in migration

* fixed issues related to auth reset; tidied up loader creator imports

* fixed auth cascade for templates of type post

* license reset running

* reset licenses on space after adding / removing license plans

* removed need for license check in community; added entitlement check in roleset when adding a VC

* remove auth reset when assigning / removing license plans

* added License to RoleSet

* added license to collaboration

* tidied up retrieval of license for whiteboard; added license to collaboration in migration

* fix typo; fix space spec file

* fix additional tests

* moved tempaltesManager to last migration in the list

* fixed retrieval of template when creating collaboration

* added logging

* fixed bootstrap setting of templates

* refactored inputCreator to do the data loading closer to usage; fixed picking up of templates; fixed bootstrap usage of templates

* added ability to retrieve limits on entitlements + current usage

* updated field names on entitlements

* updated field names on entitlements

* fixed account mutaiton logic bug

* ensure that licenses are reset when assigning beta tester or vc campaign role to a user

* added reset all account licenses mutation

* fixed bug on space entitlements; refactored code to reduce duplication

* fixed url generation for templates inside of TempaltesManager

* fixed bootstrap order to create forum earlier

* ensure collaboration creation on template provides some defaults for callouts

* fix deletion of templates of type post

* ensure more data is defaulted inside of template service for collaboration; add setting of isTemplate field on Collaboration, and also on contained Callouts

* ensure isTempalte is passed to Collaboration entity

* fixed groups in bootstrap space template; updated signature for creating callout from collaboration

* fixed missing field

* fixed type on mutation to create from collaboration

* fixed typo

* fixed groups in bootstrap space template; updated signature for creating callout from collaboration

* fixed missing field

* fixed type on mutation to create from collaboration

* fixed typo

* reworked applying collaboraiton template to collaboration

* improved error message in wrong type of ID passed in

* fixed build

* made migration last in the list

* rename migration to be last

* removed read check when looking up collaboration

* track free / plus / premium space entitlements separately

* updated migration order

* removed duplicate migration

* moved auth reset to mutation for applying the template to another collaboration

* extend lookup of entitlement usage to cover new types

* updaed license policy to reflect new entitlements; made license engine work with entitlements, not license privileges; removed license privilege (no longer relevant)

* updated migration to not drop indexes already removed

* fix for license reset on space

* added license policy rule for free space credential

* ensure license entitlements are reset as part of the bootstrap

* fixed typo

* extended reset all to include resetting licenses on accounts + AI server; moved migration to be last

* Address pr comment

* Address PR feedback

* Address PR comment

* Address PR comments

* Address PR comments

* Address PR comment

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Improved types & naming

* Address PR comments

* Fixed switch-case logic in entitlements

* Converge entitlements schema

* Remove unused AuthorizationPrivilege

* pass in spaceID on space authorization as reload the entity

* initial rework of the space authorization to clean up logic so that the Space does not know about the parent account authorization

* removed privileges on space that are no longer used there

* minor tidy up

* fixed logic check: space auth does need license entitlements

* renamed the two ways for assigning entitlements

* fix compilation:

* renaming; code setup

* take rabbit suggestion

* simplify usage of wingback api setup

* added flag to be able to disable wingback

* fix build

* fix build

* fix build

* TypeОRM default timezone to be UTC (#4732)

* typeorm default timezone to be UTC

* timezone read from the config

* Added comment about default timezone

---------

Co-authored-by: Neil Smyth <[email protected]>
Co-authored-by: Valentin Yanakiev <[email protected]>

* In-app notifications  (#4760)

* wip

* wip

* wip

* wip

* wip

* handled empty arrays

* fix for new member notification

* update state mutation

* rename

* wip

* wip

* wip

* wip

* connection to remote service

* wip

* new fields

* typeorm default timezone to be UTC

* timezone read from the config

* return sorted result by time triggered

* category is the proper type

* commentUrl on user mentioned

* graphql enums redefined

* notifications limited to beta testers only

* fixed tests

* renamed migrations to be on top

* version bump

* timezone changes reverted

* timezone changes reverted from config

* update state authorization

* removed notificationsAll query

* redundant code

* reviewer suggestions

* getAgent -> getAgentOrFail

* first set of review changes

* improved updating state

* introducing mixin to avoid CD

* removed unused extends from mixin

* added mixin for other concrete classes

---------

Co-authored-by: Svetoslav <[email protected]>
Co-authored-by: bobbykolev <[email protected]>

* Async invoke all engines ingest (#4766)

* Async invoke all engines ingest

* Reviewer suggestions

* Revert unused code

* notification dates properly serialized

* dataloader output order must match key order (#4770)

* Propagate anonymousReadAccess from parentAuthorization for Space

* dataloader can now resolve to null for nullable fields

* Fixed imports

* proper return type

* Update src/services/external/wingback/wingback.manager.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Auto stash before merge of "wingback" and "origin/wingback"

* Update src/platform/licensing/wingback-subscription/licensing.wingback.subscription.service.spec.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fixed comments / test issue

* IAN mention includes comment origin name (#4780)

* mention includes comment origin name

* package version bump

* added correct description to the field

* New callouts to be on top (#4781)

* introduce AlkemioVirtualContributorEngine for OpenAI generic and assistant engines

* update quickstart-services

* add powerpoint mimetypes (#4784)

* 7327 Don't allow nameIds on createSubspaceInput (#4785)

Co-authored-by: Valentin Yanakiev <[email protected]>

* correct contributor data loader

---------

Co-authored-by: Svetoslav <[email protected]>
Co-authored-by: Neil Smyth <[email protected]>
Co-authored-by: Neil Smyth <[email protected]>
Co-authored-by: Carlos Cano <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: bobbykolev <[email protected]>
Co-authored-by: Evgeni Dimitrov <[email protected]>
Co-authored-by: Vladimir Aleksiev <[email protected]>
Co-authored-by: Vladimir Aleksiev <[email protected]>
  • Loading branch information
10 people authored Dec 16, 2024
2 parents b4e3079 + 1cde0fd commit b497da7
Show file tree
Hide file tree
Showing 153 changed files with 2,698 additions and 1,105 deletions.
9 changes: 9 additions & 0 deletions alkemio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ search:
# The dash at the end is MANDATORY
index_pattern: ${ELASTIC_SEARCH_INDEX_PATTERN}:alkemio-data-

licensing:
wingback:
enabled: ${LICENSING_WINGBACK_ENABLED}:false
key: ${LICENSING_WINGBACK_API_KEY}
endpoint: ${LICENSING_WINGBACK_API_ENDPOINT}

## identity ##

# Defines all authentication and authorization configuration.
Expand Down Expand Up @@ -296,6 +302,9 @@ storage:
# MySQL username.
username: 'root'

# The timezone in which typeorm will interpret the dates. Default is Z for UTC
timezone: ${TYPEORM_TIMEZONE}:Z

# MySQL password.
password: ${MYSQL_ROOT_PASSWORD}:toor

Expand Down
1,251 changes: 523 additions & 728 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alkemio-server",
"version": "0.97.1",
"version": "0.98.0",
"description": "Alkemio server, responsible for managing the shared Alkemio platform",
"author": "Alkemio Foundation",
"private": false,
Expand Down Expand Up @@ -56,7 +56,7 @@
},
"dependencies": {
"@alkemio/matrix-adapter-lib": "^0.4.1",
"@alkemio/notifications-lib": "^0.9.7",
"@alkemio/notifications-lib": "0.10.1",
"@apollo/server": "^4.10.4",
"@elastic/elasticsearch": "^8.12.2",
"@golevelup/nestjs-rabbitmq": "^5.3.0",
Expand Down Expand Up @@ -87,7 +87,7 @@
"class-validator": "0.14.0",
"cookie-parser": "^1.4.6",
"cross-env": "^7.0.3",
"dataloader": "^2.2.2",
"dataloader": "^2.2.3",
"graphql": "^16.9.0",
"graphql-amqp-subscriptions": "^2.0.0",
"graphql-helix": "^1.13.0",
Expand Down
10 changes: 8 additions & 2 deletions quickstart-services-ai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ services:
virtual_contributor_engine_generic:
container_name: alkemio_dev_virtual_contributor_engine_generic
hostname: virtual-contributor-engine-generic
image: alkemio/virtual-contributor-engine-generic:v0.1.1
image: alkemio/virtual-contributor-engine-generic:v0.3.1
platform: linux/x86_64
restart: always
volumes:
Expand All @@ -507,6 +507,9 @@ services:
- RABBITMQ_PASSWORD
- RABBITMQ_PORT
- RABBITMQ_QUEUE=virtual-contributor-engine-generic
- RABBITMQ_EVENT_BUS_EXCHANGE
- RABBITMQ_RESULT_QUEUE
- RABBITMQ_RESULT_ROUTING_KEY
- LOCAL_PATH=./
- LOG_LEVEL=DEBUG
- LANGCHAIN_TRACING_V2
Expand All @@ -518,7 +521,7 @@ services:
virtual_contributor_engine_openai_assistant:
container_name: alkemio_dev_virtual_contributor_engine_openai_assistant
hostname: virtual-contributor-engine-openai-assistant
image: alkemio/virtual-contributor-engine-openai-assistant:v0.1.0
image: alkemio/virtual-contributor-engine-openai-assistant:v0.1.1
platform: linux/x86_64
restart: always
volumes:
Expand All @@ -534,5 +537,8 @@ services:
- RABBITMQ_PASSWORD
- RABBITMQ_PORT
- RABBITMQ_QUEUE=virtual-contributor-engine-openai-assistant
- RABBITMQ_EVENT_BUS_EXCHANGE
- RABBITMQ_RESULT_QUEUE
- RABBITMQ_RESULT_ROUTING_KEY
- LOCAL_PATH=./
- LOG_LEVEL=DEBUG
11 changes: 9 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import {
UnhandledExceptionFilter,
} from '@core/error-handling';
import { MeModule } from '@services/api/me';
import { ExcalidrawServerModule } from '@services/external/excalidraw-backend';
import { ChatGuidanceModule } from '@services/api/chat-guidance/chat.guidance.module';
import { LookupModule } from '@services/api/lookup';
import { AuthResetSubscriberModule } from '@services/auth-reset/subscriber/auth-reset.subscriber.module';
Expand All @@ -85,6 +84,10 @@ import { TemplateApplierModule } from '@domain/template/template-applier/templat
import { LoaderCreatorModule } from '@core/dataloader/creators/loader.creator.module';
import { Cipher, EncryptionModule } from '@hedger/nestjs-encryption';
import { AdminUsersModule } from '@platform/admin/users/admin.users.module';
import { InAppNotificationReaderModule } from '@domain/in-app-notification-reader/in.app.notification.reader.module';
import { InAppNotificationReceiverModule } from '@domain/in-app-notification-receiver';
import { LicensingWingbackSubscriptionModule } from '@platform/licensing/wingback-subscription/licensing.wingback.subscription.module';
import { WingbackManagerModule } from '@services/external/wingback/wingback.manager.module';

@Module({
imports: [
Expand Down Expand Up @@ -139,6 +142,7 @@ import { AdminUsersModule } from '@platform/admin/users/admin.users.module';
entities: [join(__dirname, '**', '*.entity.{ts,js}')],
host: dbOptions.host,
port: dbOptions.port,
timezone: dbOptions.timezone,
charset: dbOptions.charset,
username: dbOptions.username,
password: dbOptions.password,
Expand Down Expand Up @@ -264,6 +268,8 @@ import { AdminUsersModule } from '@platform/admin/users/admin.users.module';
AdminCommunicationModule,
AdminSearchIngestModule,
AdminLicensingModule,
LicensingWingbackSubscriptionModule,
WingbackManagerModule,
AgentModule,
MessageModule,
MessageReactionModule,
Expand All @@ -281,7 +287,6 @@ import { AdminUsersModule } from '@platform/admin/users/admin.users.module';
SsiCredentialFlowModule,
StorageAccessModule,
MeModule,
ExcalidrawServerModule,
ChatGuidanceModule,
VirtualContributorModule,
InputCreatorModule,
Expand All @@ -295,6 +300,8 @@ import { AdminUsersModule } from '@platform/admin/users/admin.users.module';
FileIntegrationModule,
PlatformSettingsModule,
TemplateApplierModule,
InAppNotificationReaderModule,
InAppNotificationReceiverModule,
],
controllers: [AppController, SsiCredentialFlowController],
providers: [
Expand Down
8 changes: 5 additions & 3 deletions src/common/enums/credential.type.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { registerEnumType } from '@nestjs/graphql';
import { LicenseCredential } from './license.credential';
import { LicensingCredentialBasedCredentialType } from './licensing.credential.based.credential.type';
import { AuthorizationCredential } from './authorization.credential';

export const CredentialType = {
...LicenseCredential,
...LicensingCredentialBasedCredentialType,
...AuthorizationCredential,
};

export type CredentialType = LicenseCredential | AuthorizationCredential;
export type CredentialType =
| LicensingCredentialBasedCredentialType
| AuthorizationCredential;

registerEnumType(CredentialType, {
name: 'CredentialType',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { registerEnumType } from '@nestjs/graphql';

// Credentials to be added later:
export enum LicenseCredential {
export enum LicensingCredentialBasedCredentialType {
SPACE_LICENSE_FREE = 'space-license-free',
SPACE_LICENSE_PLUS = 'space-license-plus',
SPACE_LICENSE_PREMIUM = 'space-license-premium',
Expand All @@ -12,6 +12,6 @@ export enum LicenseCredential {
ACCOUNT_LICENSE_PLUS = 'account-license-plus',
}

registerEnumType(LicenseCredential, {
name: 'LicenseCredential',
registerEnumType(LicensingCredentialBasedCredentialType, {
name: 'LicensingCredentialBasedCredentialType',
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { registerEnumType } from '@nestjs/graphql';

export enum LicensePlanType {
export enum LicensingCredentialBasedPlanType {
ACCOUNT_FEATURE_FLAG = 'account-feature-flag',
ACCOUNT_PLAN = 'account-plan',
SPACE_PLAN = 'space-plan',
SPACE_FEATURE_FLAG = 'space-feature-flag',
}

registerEnumType(LicensePlanType, {
name: 'LicensePlanType',
registerEnumType(LicensingCredentialBasedPlanType, {
name: 'LicensingCredentialBasedPlanType',
});
11 changes: 11 additions & 0 deletions src/common/enums/licensing.wingback.subscription.feature.name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { registerEnumType } from '@nestjs/graphql';

export enum LicensingWingbackSubscriptionFeatureName {
ACCOUNT_SPACE_FREE = 'account-space-free',
ACCOUNT_SPACE_PLUS = 'account-space-plus',
ACCOUNT_SPACE_PREMIUM = 'account-space-premium',
}

registerEnumType(LicensingWingbackSubscriptionFeatureName, {
name: 'LicensingWingbackSubscriptionFeatureName',
});
1 change: 1 addition & 0 deletions src/common/enums/logging.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum LogContext {
COLLABORATION = 'collaboration',
AGENT = 'agent',
ACTIVITY = 'activity',
IN_APP_NOTIFICATION = 'in-app-notification',
ACTIVITY_FEED = 'activity-feed',
API = 'api',
AUTH = 'auth',
Expand Down
1 change: 1 addition & 0 deletions src/common/enums/messaging.queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export enum MessagingQueue {
//
WHITEBOARDS = 'alkemio-whiteboards',
FILES = 'alkemio-files',
IN_APP_NOTIFICATIONS = 'alkemio-in-app-notifications',
}
9 changes: 9 additions & 0 deletions src/common/enums/mime.file.type.document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ export enum MimeTypeDocument {
DOC = 'application/msword',
DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
ODT = 'application/vnd.oasis.opendocument.text',

PPT = 'application/vnd.ms-powerpoint',
PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
ODP = 'application/vnd.oasis.opendocument.presentation',
PPTM = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
PPSX = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
PPSM = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
POTX = 'application/vnd.openxmlformats-officedocument.presentationml.template',
POTM = 'application/vnd.ms-powerpoint.template.macroEnabled.12',
}

registerEnumType(MimeTypeDocument, {
Expand Down
5 changes: 3 additions & 2 deletions src/common/exceptions/forbidden.exception.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AlkemioErrorStatus, LogContext } from '@common/enums';
import { BaseException } from './base.exception';
import { ExceptionDetails } from '@common/exceptions/exception.details';

export class ForbiddenException extends BaseException {
constructor(error: string, context: LogContext, code?: AlkemioErrorStatus) {
super(error, context, code ?? AlkemioErrorStatus.FORBIDDEN);
constructor(error: string, context: LogContext, details?: ExceptionDetails) {
super(error, context, AlkemioErrorStatus.FORBIDDEN, details);
}
}
25 changes: 25 additions & 0 deletions src/common/utils/compare.enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Compares two TypeScript enums for equality
* @param enum1 First enum to compare
* @param enum2 Second enum to compare
* @returns boolean indicating if enums are equal
*/
export const compareEnums = <T extends { [key: string]: string | number }>(
enum1: T,
enum2: T
): boolean => {
const keys1 = Object.keys(enum1);
const keys2 = Object.keys(enum2);

if (keys1.length !== keys2.length) {
return false;
}

for (const key of keys1) {
if (enum1[key] !== enum2[key]) {
return false;
}
}

return true;
};
1 change: 1 addition & 0 deletions src/common/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './path.resolve';
export * from './get-differences';
export * from './has-allowed-allowed-fields';
export * from './convert-to-entity';
export * from './compare.enums';
4 changes: 2 additions & 2 deletions src/core/bootstrap/bootstrap.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { TemplatesSetModule } from '@domain/template/templates-set/templates.set
import { TemplatesManagerModule } from '@domain/template/templates-manager/templates.manager.module';
import { TemplateDefaultModule } from '@domain/template/template-default/template.default.module';
import { LicenseModule } from '@domain/common/license/license.module';
import { LicensePlanModule } from '@platform/license-plan/license.plan.module';
import { LicensingFrameworkModule } from '@platform/licensing-framework/licensing.framework.module';
import { AiPersonaServiceModule } from '@services/ai-server/ai-persona-service/ai.persona.service.module';
import { LicensingFrameworkModule } from '@platform/licensing/credential-based/licensing-framework/licensing.framework.module';
import { LicensePlanModule } from '@platform/licensing/credential-based/license-plan/license.plan.module';

@Module({
imports: [
Expand Down
6 changes: 3 additions & 3 deletions src/core/bootstrap/bootstrap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ import { bootstrapSpaceTutorialsCalloutGroups } from './platform-template-defini
import { bootstrapSpaceTutorialsCallouts } from './platform-template-definitions/space-tutorials/bootstrap.space.tutorials.callouts';
import { LicenseService } from '@domain/common/license/license.service';
import { AccountLicenseService } from '@domain/space/account/account.service.license';
import { LicensePlanService } from '@platform/license-plan/license.plan.service';
import { LicensingFrameworkService } from '@platform/licensing-framework/licensing.framework.service';
import { LicensePlanService } from '@platform/licensing/credential-based/license-plan/license.plan.service';
import { LicensingFrameworkService } from '@platform/licensing/credential-based/licensing-framework/licensing.framework.service';
import { AiPersonaServiceService } from '@services/ai-server/ai-persona-service/ai.persona.service.service';
import { AiPersonaEngine } from '@common/enums/ai.persona.engine';
import { AiPersonaBodyOfKnowledgeType } from '@common/enums/ai.persona.body.of.knowledge.type';
Expand Down Expand Up @@ -520,7 +520,7 @@ export class BootstrapService {

const space = await this.accountService.createSpaceOnAccount(spaceInput);
const spaceAuthorizations =
await this.spaceAuthorizationService.applyAuthorizationPolicy(space);
await this.spaceAuthorizationService.applyAuthorizationPolicy(space.id);
await this.authorizationPolicyService.saveAll(spaceAuthorizations);

const accountEntitlements =
Expand Down
5 changes: 4 additions & 1 deletion src/core/dataloader/creators/base/data.loader.creator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { ILoader } from '../../loader.interface';
import { DataLoaderCreatorOptions } from './data.loader.creator.options';
import { EntityNotFoundException } from '@common/exceptions';

export interface DataLoaderCreator<TReturn> {
create(options?: DataLoaderCreatorOptions<TReturn>): ILoader<TReturn>;
create(
options?: DataLoaderCreatorOptions<TReturn>
): ILoader<TReturn | null | EntityNotFoundException>;
}
1 change: 1 addition & 0 deletions src/core/dataloader/creators/base/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './data.loader.creator';

export * from './data.loader.creator.base.options';
export * from './data.loader.creator.options';
export * from './data.loader.creator.limit.options';
export * from './data.loader.creator.pagination.options';
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { EntityManager, In } from 'typeorm';
import { Injectable } from '@nestjs/common';
import { InjectEntityManager } from '@nestjs/typeorm';
import {
DataLoaderCreator,
DataLoaderCreatorBaseOptions,
} from '@core/dataloader/creators/base';
import { createBatchLoader } from '@core/dataloader/utils';
import { ILoader } from '@core/dataloader/loader.interface';
import { Callout, ICallout } from '@domain/collaboration/callout';
import { EntityNotFoundException } from '@common/exceptions';

@Injectable()
export class CalloutLoaderCreator implements DataLoaderCreator<ICallout> {
constructor(@InjectEntityManager() private manager: EntityManager) {}

public create(
options?: DataLoaderCreatorBaseOptions<any, any>
): ILoader<ICallout | null | EntityNotFoundException> {
return createBatchLoader(this.calloutInBatch, {
name: this.constructor.name,
loadedTypeName: Callout.name,
resolveToNull: options?.resolveToNull,
});
}

private calloutInBatch = (
keys: ReadonlyArray<string>
): Promise<Callout[]> => {
return this.manager.findBy(Callout, { id: In(keys) });
};
}
Loading

0 comments on commit b497da7

Please sign in to comment.