Skip to content

Commit

Permalink
[#15] feat - Add MediaRelation schema
Browse files Browse the repository at this point in the history
Co-authored-by: Leonardo Barreiros <leossb36@gmail.com>
  • Loading branch information
guilherme1guy and leossb36 committed Sep 28, 2021
1 parent fefa126 commit e1faa51
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/mapas/entities/MediaRelation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type MediaRelationDocument = MediaRelation & Document;

@Schema()
export class MediaRelation {
@Prop()
mediaId: string;

@Prop()
locationID: string;
}

export const MediaRelationSchema = SchemaFactory.createForClass(MediaRelation);

MediaRelationSchema.virtual('id').get(function () {
return this._id.toHexString();
});

MediaRelationSchema.virtual('dateAdded').get(function () {
return this._id.getTimestamp();
});

MediaRelationSchema.set('toJSON', {
virtuals: true,
transform: function (doc, ret) {
delete ret._id;
delete ret.__v;
},
});
4 changes: 4 additions & 0 deletions src/mapas/mapas.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import { MapasController } from './mapas.controller';
import { MongooseModule } from '@nestjs/mongoose';
import { Point, PointSchema } from './entities/point.schema';
import { Area, AreaSchema } from './entities/area.schema';
import { MediaRelation, MediaRelationSchema } from './entities/MediaRelation';

@Module({
imports: [
MongooseModule.forFeature([{ name: Point.name, schema: PointSchema }]),
MongooseModule.forFeature([{ name: Area.name, schema: AreaSchema }]),
MongooseModule.forFeature([
{ name: MediaRelation.name, schema: MediaRelationSchema },
]),
],
controllers: [MapasController],
providers: [MapasService],
Expand Down
5 changes: 5 additions & 0 deletions test/mapas/mapas.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getModelToken } from '@nestjs/mongoose';
import { Test, TestingModule } from '@nestjs/testing';
import { MediaRelation } from '../../src/mapas/entities/MediaRelation';
import { Area } from '../../src/mapas/entities/area.schema';
import { Point } from '../../src/mapas/entities/point.schema';
import { MapasController } from '../../src/mapas/mapas.controller';
Expand All @@ -25,6 +26,10 @@ describe('MapasController', () => {
provide: getModelToken(Area.name),
useValue: jest.fn(),
},
{
provide: getModelToken(MediaRelation.name),
useValue: jest.fn(),
},
],
}).compile();
};
Expand Down
11 changes: 10 additions & 1 deletion test/mapas/mapas.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MicrosserviceException } from '../../src/commons/exceptions/Microsservi
import { Area } from '../../src/mapas/entities/area.schema';
import { Point } from '../../src/mapas/entities/point.schema';
import { MapasService } from '../../src/mapas/mapas.service';
import { MediaRelation } from '../../src/mapas/entities/MediaRelation';

describe('MapasService', () => {
let service: MapasService;
Expand All @@ -17,7 +18,11 @@ describe('MapasService', () => {
};
}

const dynamicModule = (fn: any, areaFn: any = jest.fn()) => {
const dynamicModule = (
fn: any,
areaFn: any = jest.fn(),
mediaFn: any = jest.fn(),
) => {
return Test.createTestingModule({
providers: [
MapasService,
Expand All @@ -29,6 +34,10 @@ describe('MapasService', () => {
provide: getModelToken(Area.name),
useValue: areaFn,
},
{
provide: getModelToken(MediaRelation.name),
useValue: mediaFn,
},
],
}).compile();
};
Expand Down

0 comments on commit e1faa51

Please sign in to comment.