Skip to content

Commit

Permalink
N21-1512 Fix SchoolExternalTool metadata (#4580)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap authored Nov 27, 2023
1 parent b90f460 commit 537571d
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 30 deletions.
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({
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;
}
}

0 comments on commit 537571d

Please sign in to comment.