Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N21-1512 Fix SchoolExternalTool metadata #4580

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ApiProperty } from '@nestjs/swagger';

export class ContextExternalToolCountPerContextResponse {
@ApiProperty()
course: number;

@ApiProperty()
boardElement: number;

constructor(props: ContextExternalToolCountPerContextResponse) {
this.course = props.course;
this.boardElement = props.boardElement;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ContextExternalToolCountPerContextResponse } from './context-external-tool-count-per-context.response';
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';
import { ContextExternalToolType } from '../../../../context-external-tool/entity';
import { ContextExternalToolCountPerContextResponse } from '../../../../common/controller/dto';

export class ExternalToolMetadataResponse {
@ApiProperty()
schoolExternalToolCount: number;

@ApiProperty({
type: 'object',
properties: Object.fromEntries(
Object.values(ContextExternalToolType).map((key: ContextExternalToolType) => [key, { type: 'number' }])
),
})
contextExternalToolCountPerContext: Record<ContextExternalToolType, number>;
@ApiProperty()
contextExternalToolCountPerContext: ContextExternalToolCountPerContextResponse;

constructor(externalToolMetadataResponse: ExternalToolMetadataResponse) {
this.schoolExternalToolCount = externalToolMetadataResponse.schoolExternalToolCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ContextExternalToolType } from '../../context-external-tool/entity';

export class ExternalToolMetadata {
schoolExternalToolCount: number;

contextExternalToolCountPerContext: Record<string, number>;
contextExternalToolCountPerContext: Record<ContextExternalToolType, number>;

constructor(externalToolMetadata: ExternalToolMetadata) {
this.schoolExternalToolCount = externalToolMetadata.schoolExternalToolCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ContextExternalToolCountPerContextResponse } from '../../common/controller/dto';
import { ExternalToolMetadataResponse } from '../controller/dto';
import { ExternalToolMetadata } from '../domain';

export class ExternalToolMetadataMapper {
static mapToExternalToolMetadataResponse(externalToolMetadata: ExternalToolMetadata): ExternalToolMetadataResponse {
const externalToolMetadataResponse: ExternalToolMetadataResponse = new ExternalToolMetadataResponse({
schoolExternalToolCount: externalToolMetadata.schoolExternalToolCount,
contextExternalToolCountPerContext: externalToolMetadata.contextExternalToolCountPerContext,
contextExternalToolCountPerContext: new ContextExternalToolCountPerContextResponse(
externalToolMetadata.contextExternalToolCountPerContext
),
});

return externalToolMetadataResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Injectable } from '@nestjs/common';
import { EntityId } from '@shared/domain';
import { ContextExternalToolRepo, SchoolExternalToolRepo } from '@shared/repo';
import { ToolContextType } from '../../common/enum';
import { ToolContextMapper } from '../../common/mapper/tool-context.mapper';
import { ContextExternalToolType } from '../../context-external-tool/entity';
import { SchoolExternalTool } from '../../school-external-tool/domain';
import { ExternalToolMetadata } from '../domain';
import { ToolContextMapper } from '../../common/mapper/tool-context.mapper';

@Injectable()
export class ExternalToolMetadataService {
Expand Down Expand Up @@ -40,11 +40,11 @@ export class ExternalToolMetadataService {
);
}

const externaltoolMetadata: ExternalToolMetadata = new ExternalToolMetadata({
const externalToolMetadata: ExternalToolMetadata = new ExternalToolMetadata({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

schoolExternalToolCount: schoolExternalTools.length,
contextExternalToolCountPerContext: contextExternalToolCount,
});

return externaltoolMetadata;
return externalToolMetadata;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { IFindOptions, Permission, Role, SortOrder, User } from '@shared/domain';
import { Page } from '@shared/domain/domainobject/page';
import { roleFactory, setupEntities, userFactory } from '@shared/testing';
import {
externalToolFactory,
oauth2ToolConfigFactory,
} from '@shared/testing/factory/domainobject/tool/external-tool.factory';
import { externalToolFactory, oauth2ToolConfigFactory } from '@shared/testing/factory';
import { ExternalToolSearchQuery } from '../../common/interface';
import { ExternalTool, ExternalToolMetadata, Oauth2ToolConfig } from '../domain';
import {
Expand Down Expand Up @@ -550,7 +547,7 @@ describe('ExternalToolUc', () => {

const externalToolMetadata: ExternalToolMetadata = new ExternalToolMetadata({
schoolExternalToolCount: 2,
contextExternalToolCountPerContext: { course: 3, 'board-element': 3 },
contextExternalToolCountPerContext: { course: 3, boardElement: 3 },
});

externalToolMetadataService.getMetadata.mockResolvedValue(externalToolMetadata);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { ContextExternalToolType } from '../../../context-external-tool/entity';
import { ContextExternalToolCountPerContextResponse } from '../../../common/controller/dto';

export class SchoolExternalToolMetadataResponse {
@ApiProperty({
type: 'object',
properties: Object.fromEntries(
Object.values(ContextExternalToolType).map((key: ContextExternalToolType) => [key, { type: 'number' }])
),
})
contextExternalToolCountPerContext: Record<ContextExternalToolType, number>;
@ApiProperty()
contextExternalToolCountPerContext: ContextExternalToolCountPerContextResponse;

constructor(schoolExternalToolMetadataResponse: SchoolExternalToolMetadataResponse) {
this.contextExternalToolCountPerContext = schoolExternalToolMetadataResponse.contextExternalToolCountPerContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ContextExternalToolType } from '../../context-external-tool/entity';

export class SchoolExternalToolMetadata {
contextExternalToolCountPerContext: Record<string, number>;
contextExternalToolCountPerContext: Record<ContextExternalToolType, number>;

constructor(schoolExternalToolMetadata: SchoolExternalToolMetadata) {
this.contextExternalToolCountPerContext = schoolExternalToolMetadata.contextExternalToolCountPerContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ContextExternalToolCountPerContextResponse } from '../../common/controller/dto';
import { SchoolExternalToolMetadataResponse } from '../controller/dto';
import { SchoolExternalToolMetadata } from '../domain';

Expand All @@ -6,7 +7,9 @@ export class SchoolExternalToolMetadataMapper {
schoolExternalToolMetadata: SchoolExternalToolMetadata
): SchoolExternalToolMetadataResponse {
const externalToolMetadataResponse: SchoolExternalToolMetadataResponse = new SchoolExternalToolMetadataResponse({
contextExternalToolCountPerContext: schoolExternalToolMetadata.contextExternalToolCountPerContext,
contextExternalToolCountPerContext: new ContextExternalToolCountPerContextResponse(
schoolExternalToolMetadata.contextExternalToolCountPerContext
),
});

return externalToolMetadataResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export class SchoolExternalToolMetadataService {
})
);

const schoolExternaltoolMetadata: SchoolExternalToolMetadata = new SchoolExternalToolMetadata({
const schoolExternalToolMetadata: SchoolExternalToolMetadata = new SchoolExternalToolMetadata({
contextExternalToolCountPerContext: contextExternalToolCount,
});

return schoolExternaltoolMetadata;
return schoolExternalToolMetadata;
}
}
Loading