Skip to content

Commit

Permalink
chore: fix problem with api generator
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeppner-dataport committed Sep 29, 2023
1 parent bff9a03 commit 743ed53
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 56 deletions.
13 changes: 8 additions & 5 deletions apps/server/src/modules/board/controller/card.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
CreateContentElementBodyParams,
ExternalToolElementResponse,
FileElementResponse,
LinkElementResponse,
MoveCardBodyParams,
RenameBodyParams,
RichTextElementResponse,
Expand Down Expand Up @@ -116,19 +117,21 @@ export class CardController {

@ApiOperation({ summary: 'Create a new element on a card.' })
@ApiExtraModels(
RichTextElementResponse,
ExternalToolElementResponse,
FileElementResponse,
SubmissionContainerElementResponse,
ExternalToolElementResponse
LinkElementResponse,
RichTextElementResponse,
SubmissionContainerElementResponse
)
@ApiResponse({
status: 201,
schema: {
oneOf: [
{ $ref: getSchemaPath(RichTextElementResponse) },
{ $ref: getSchemaPath(ExternalToolElementResponse) },
{ $ref: getSchemaPath(FileElementResponse) },
{ $ref: getSchemaPath(LinkElementResponse) },
{ $ref: getSchemaPath(RichTextElementResponse) },
{ $ref: getSchemaPath(SubmissionContainerElementResponse) },
{ $ref: getSchemaPath(ExternalToolElementResponse) },
],
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import {
import { TimestampsResponse } from '../timestamps.response';
import { VisibilitySettingsResponse } from './visibility-settings.response';

@ApiExtraModels(LinkElementResponse, RichTextElementResponse)
@ApiExtraModels(
ExternalToolElementResponse,
FileElementResponse,
LinkElementResponse,
RichTextElementResponse,
SubmissionContainerElementResponse
)
export class CardResponse {
constructor({ id, title, height, elements, visibilitySettings, timestamps }: CardResponse) {
this.id = id;
Expand Down Expand Up @@ -40,9 +46,9 @@ export class CardResponse {
oneOf: [
{ $ref: getSchemaPath(ExternalToolElementResponse) },
{ $ref: getSchemaPath(FileElementResponse) },
{ $ref: getSchemaPath(LinkElementResponse) },
{ $ref: getSchemaPath(RichTextElementResponse) },
{ $ref: getSchemaPath(SubmissionContainerElementResponse) },
{ $ref: getSchemaPath(LinkElementResponse) },
],
},
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
import { ApiExtraModels, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ContentElementType } from '@shared/domain';
import { OpenGraphData } from '@src/modules/board/service';
import { TimestampsResponse } from '../timestamps.response';

@ApiExtraModels(OpenGraphData)
export class OpenGraphImageData {
constructor({ url, type, width, height }: OpenGraphImageData) {
this.url = url;
this.type = type;
this.width = width ? +width : undefined;
this.height = height ? +height : undefined;
}

@ApiProperty()
url: string;

@ApiPropertyOptional()
type?: string;

@ApiPropertyOptional()
width?: number;

@ApiPropertyOptional()
height?: number;
}

export class OpenGraphData {
constructor({ title, description, image, url }: OpenGraphData) {
this.title = title;
this.description = description;
this.image = image;
this.url = url;
}

@ApiProperty()
title: string;

@ApiProperty()
description: string;

@ApiPropertyOptional({ type: OpenGraphImageData })
image?: OpenGraphImageData;

@ApiProperty()
url: string;
}
export class LinkElementContent {
constructor({ url, openGraphData }: LinkElementContent) {
this.url = url;
Expand All @@ -13,7 +52,7 @@ export class LinkElementContent {
@ApiProperty()
url: string;

@ApiPropertyOptional({ type: 'OpenGraphData' })
@ApiPropertyOptional({ type: OpenGraphData })
openGraphData?: OpenGraphData;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,8 @@
import { Injectable } from '@nestjs/common';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { sortBy } from 'lodash';
import ogs from 'open-graph-scraper';
import { ImageObject } from 'open-graph-scraper/dist/lib/types';

export class OpenGraphImageData {
constructor({ url, type, width, height }: OpenGraphImageData) {
this.url = url;
this.type = type;
this.width = width ? +width : undefined;
this.height = height ? +height : undefined;
}

@ApiProperty()
url: string;

@ApiPropertyOptional()
type?: string;

@ApiPropertyOptional()
width?: number;

@ApiPropertyOptional()
height?: number;
}

export class OpenGraphData {
constructor({ title, description, image, url }: OpenGraphData) {
this.title = title;
this.description = description;
this.image = image;
this.url = url;
}

@ApiProperty()
title: string;

@ApiProperty()
description: string;

@ApiPropertyOptional()
image?: OpenGraphImageData;

@ApiProperty()
url: string;
}
import { OpenGraphData, OpenGraphImageData } from '../controller/dto';

@Injectable()
export class OpenGraphProxyService {
Expand All @@ -70,7 +28,6 @@ export class OpenGraphProxyService {
const sortedImages = sortBy(imagesWithCorrectDimensions, ['width', 'height']);
const biggestSmallEnoughImage = [...sortedImages].reverse().find((i) => i.width && i.width <= maxWidth);
const smallestBigEnoughImage = sortedImages.find((i) => i.width && i.width >= minWidth);
// return imagesWithCorrectDimensions[0];
return biggestSmallEnoughImage ?? smallestBigEnoughImage ?? sortedImages[0];
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenGraphData } from '@src/modules/board/service';
import { OpenGraphData } from '@src/modules/board/controller/dto';
import { BoardComposite, BoardCompositeProps } from './board-composite.do';
import type { BoardCompositeVisitor, BoardCompositeVisitorAsync } from './types';

Expand Down

0 comments on commit 743ed53

Please sign in to comment.