-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
N21-1319 schoolexternaltool metadata
- Loading branch information
Showing
7 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...odules/tool/school-external-tool/controller/dto/school-external-tool-metadata.response.ts
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,11 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { ToolContextType } from '../../../common/enum'; | ||
|
||
export class SchoolExternalToolMetadataResponse { | ||
@ApiProperty() | ||
contextExternalToolCountPerContext: Map<ToolContextType, number>; | ||
|
||
constructor(schoolExternalToolMetadataResponse: SchoolExternalToolMetadataResponse) { | ||
this.contextExternalToolCountPerContext = schoolExternalToolMetadataResponse.contextExternalToolCountPerContext; | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
apps/server/src/modules/tool/school-external-tool/domain/school-external-tool-metadata.ts
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,9 @@ | ||
import { ToolContextType } from '../../common/enum'; | ||
|
||
export class SchoolExternalToolMetadata { | ||
contextExternalToolCountPerContext: Map<ToolContextType, number>; | ||
|
||
constructor(schoolExternalToolMetadata: SchoolExternalToolMetadata) { | ||
this.contextExternalToolCountPerContext = schoolExternalToolMetadata.contextExternalToolCountPerContext; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...rver/src/modules/tool/school-external-tool/mapper/school-external-tool-metadata.mapper.ts
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,14 @@ | ||
import { SchoolExternalToolMetadataResponse } from '../controller/dto/school-external-tool-metadata.response'; | ||
import { SchoolExternalToolMetadata } from '../domain/school-external-tool-metadata'; | ||
|
||
export class SchoolExternalToolMetadataMapper { | ||
static mapToSchoolExternalToolMetadataResponse( | ||
schoolExternalToolMetadata: SchoolExternalToolMetadata | ||
): SchoolExternalToolMetadataResponse { | ||
const externalToolMetadataResponse: SchoolExternalToolMetadataResponse = new SchoolExternalToolMetadataResponse({ | ||
contextExternalToolCountPerContext: schoolExternalToolMetadata.contextExternalToolCountPerContext, | ||
}); | ||
|
||
return externalToolMetadataResponse; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...er/src/modules/tool/school-external-tool/service/school-external-tool-metadata.service.ts
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,78 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { EntityId } from '@shared/domain'; | ||
import { ContextExternalToolRepo, ExternalToolRepo, SchoolExternalToolRepo } from '@shared/repo'; | ||
import { Logger } from '../../../../core/logger'; | ||
import { ToolContextType } from '../../common/enum'; | ||
import { SchoolExternalToolMetadata } from '../domain/school-external-tool-metadata'; | ||
|
||
@Injectable() | ||
export class SchoolExternalToolMetadataService { | ||
constructor( | ||
private readonly logger: Logger, | ||
private readonly externalToolRepo: ExternalToolRepo, | ||
private readonly schoolToolRepo: SchoolExternalToolRepo, | ||
private readonly contextToolRepo: ContextExternalToolRepo | ||
) {} | ||
|
||
async getMetadata(schoolExternalToolId: EntityId) { | ||
const toolCountPerContext: { ToolContextType; number }[] = await Promise.all( | ||
// Context Course | ||
Object.values(ToolContextType).map( | ||
async ( | ||
contextType: ToolContextType | ||
): Promise<{ | ||
ToolContextType; | ||
number; | ||
}> => { | ||
const countPerContext: number = | ||
await this.contextToolRepo.countContextExternalToolsBySchoolToolIdAndContextType( | ||
contextType, | ||
schoolExternalToolId | ||
); | ||
return { ToolContextType: contextType, number: countPerContext }; | ||
} | ||
) | ||
); | ||
|
||
const schoolExternaltoolMetadata = this.createSchoolExternalToolMetadata(toolCountPerContext); | ||
|
||
/* const contextExternalToolMetadata: Map<ToolContextType, number> = new Map( | ||
toolCountPerContext.map((contextExternalToolCountPerSchool: { ToolContextType; number }) => [ | ||
contextExternalToolCountPerSchool.ToolContextType, | ||
contextExternalToolCountPerSchool.number, | ||
]) | ||
); | ||
const externaltoolMetadata: ExternalToolMetadata = new ExternalToolMetadata({ | ||
schoolExternalToolCount, | ||
contextExternalToolCountPerContext: contextExternalToolMetadata, | ||
}); | ||
*/ | ||
|
||
return schoolExternaltoolMetadata; | ||
} | ||
|
||
private createContextExternalToolMetaData( | ||
toolCountPerContext: { ToolContextType; number }[] | ||
): Map<ToolContextType, number> { | ||
const contextExternalToolMetadata: Map<ToolContextType, number> = new Map( | ||
toolCountPerContext.map((contextExternalToolCountPerSchool: { ToolContextType; number }) => [ | ||
contextExternalToolCountPerSchool.ToolContextType, | ||
contextExternalToolCountPerSchool.number, | ||
]) | ||
); | ||
|
||
return contextExternalToolMetadata; | ||
} | ||
|
||
private createSchoolExternalToolMetadata( | ||
contextExternalToolCountPerContext: { ToolContextType; number }[] | ||
): SchoolExternalToolMetadata { | ||
const schoolExternaltoolMetadata: SchoolExternalToolMetadata = new SchoolExternalToolMetadata({ | ||
contextExternalToolCountPerContext: this.createContextExternalToolMetaData(contextExternalToolCountPerContext), | ||
}); | ||
|
||
return schoolExternaltoolMetadata; | ||
} | ||
} |
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