Skip to content

Commit 980825b

Browse files
Merge pull request #124 from CollActionteam/119-new-fields-for-badges
add badge icon and list of crowdActionMetadata to badgeDTO
2 parents 20dc8b3 + 8174c2d commit 980825b

7 files changed

Lines changed: 52 additions & 3 deletions

File tree

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
import { AwardTypeEnum, BadgeTierEnum } from '../enum';
2-
import { IBadge } from '../interface/badge.interface';
2+
import { IBadge, ICrowdActionMetaData } from '../interface/badge.interface';
33

4+
export class CrowdActionMetaData implements ICrowdActionMetaData {
5+
readonly id: string;
6+
readonly title: string;
7+
8+
constructor(entityLike: ICrowdActionMetaData) {
9+
this.id = entityLike.id;
10+
this.title = entityLike.title;
11+
}
12+
}
413
export class Badge implements IBadge {
514
readonly tier: BadgeTierEnum;
615
readonly awardType: AwardTypeEnum;
716
readonly minimumCheckIns: number;
17+
readonly icon: string;
18+
readonly crowdActionMetaData?: ICrowdActionMetaData;
819

920
constructor(entityLike: IBadge) {
1021
this.tier = entityLike.tier;
1122
this.awardType = entityLike.awardType;
1223
this.minimumCheckIns = entityLike.minimumCheckIns;
24+
this.icon = entityLike.icon;
25+
this.crowdActionMetaData = entityLike.metadata;
1326
}
1427
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { BadgeTierEnum, AwardTypeEnum } from '../enum';
22

3+
export interface ICrowdActionMetaData {
4+
readonly id: string;
5+
readonly title: string;
6+
}
7+
38
export interface IBadge {
49
readonly tier: BadgeTierEnum;
510
readonly awardType: AwardTypeEnum;
611
readonly minimumCheckIns: number;
12+
readonly icon: string;
13+
readonly metadata?: ICrowdActionMetaData;
714
}

src/infrastructure/crowdaction/dto/badge.dto.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { ApiProperty } from '@nestjs/swagger';
2-
import { AwardTypeEnum, BadgeTierEnum, IBadge } from '@domain/badge';
2+
import { AwardTypeEnum, BadgeTierEnum, IBadge, ICrowdActionMetaData } from '@domain/badge';
3+
export class CrowdActionMetadataDTO implements ICrowdActionMetaData {
4+
@ApiProperty({ name: 'id', example: '123', required: true })
5+
readonly id: string;
6+
7+
@ApiProperty({ name: 'title', example: 'Veganuary', required: true })
8+
readonly title: string;
9+
}
310

411
export class BadgeDto implements IBadge {
512
@ApiProperty({ name: 'tier', enum: BadgeTierEnum, example: BadgeTierEnum.DIAMOND, required: true })
@@ -10,4 +17,10 @@ export class BadgeDto implements IBadge {
1017

1118
@ApiProperty({ name: 'minimumCheckIns', example: 0, required: true })
1219
readonly minimumCheckIns: number;
20+
21+
@ApiProperty({ name: 'icon', example: 'accessibility_outline', required: false })
22+
readonly icon: string;
23+
24+
@ApiProperty({ name: 'usedByCrowdActions', type: [CrowdActionMetadataDTO], isArray: true, required: true })
25+
readonly usedByCrowdActions: CrowdActionMetadataDTO[];
1326
}

src/infrastructure/mongo/persistence/badge.persistence.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2-
import { AwardTypeEnum, BadgeTierEnum, IBadge } from '@domain/badge';
2+
import { AwardTypeEnum, BadgeTierEnum, IBadge, ICrowdActionMetaData } from '@domain/badge';
33

44
@Schema({ _id: false })
55
class CrowdActionBadgePersistence implements IBadge {
@@ -11,5 +11,17 @@ class CrowdActionBadgePersistence implements IBadge {
1111

1212
@Prop({ required: true })
1313
readonly minimumCheckIns: number;
14+
15+
@Prop()
16+
readonly icon: string;
17+
18+
@Prop({ type: { id: { type: String }, title: { type: String } } })
19+
readonly usedByCrowdActions?: ICrowdActionMetaData;
20+
21+
@Prop()
22+
readonly id: string;
23+
24+
@Prop()
25+
readonly title: string;
1426
}
1527
export const CrowdActionBadgePersistenceSchema = SchemaFactory.createForClass(CrowdActionBadgePersistence);

src/modules/crowdaction/cqrs/tests/list-crowdactions.query.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ const CrowdActionStub: CreateCrowdActionDto = {
233233
{
234234
tier: BadgeTierEnum.BRONZE,
235235
awardType: AwardTypeEnum.ALL,
236+
icon: 'accessibility_outline',
236237
minimumCheckIns: 12,
237238
},
238239
],
@@ -256,6 +257,7 @@ const CrowdActionStub2: CreateCrowdActionDto = {
256257
{
257258
tier: BadgeTierEnum.DIAMOND,
258259
awardType: AwardTypeEnum.ALL,
260+
icon: 'accessibility_outline',
259261
minimumCheckIns: 12,
260262
},
261263
],

src/modules/crowdaction/tests/crowdaction.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const CrowdActionStub = (): CrowdAction => {
100100
{
101101
tier: BadgeTierEnum.BRONZE,
102102
awardType: AwardTypeEnum.ALL,
103+
icon: 'accessibility_outline',
103104
minimumCheckIns: 12,
104105
},
105106
],

src/modules/profile/cqrs/tests/award-badges.command.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('AwardBadgesCommand', () => {
5454
const badge = {
5555
tier: BadgeTierEnum.BRONZE,
5656
awardType: AwardTypeEnum.ALL,
57+
icon: 'accessibility_icon',
5758
minimumCheckIns: 10,
5859
};
5960

0 commit comments

Comments
 (0)