Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
feat: remove BatchDelete interface and use BatchDeleteModel
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Dec 27, 2019
1 parent 6e3ac59 commit 6b422e8
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 34 deletions.
10 changes: 10 additions & 0 deletions gql/player.gql
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ mutation DeletePlayer {
deletedCount
}
}

mutation SwitchIsPubilc {
switchIsPubilc(
ids: ["60e5c5a2-f69f-41df-bc04-53f9c699e498", "00c602bd-e364-491d-abb1-45cf930ac443"]
) {
n
ok
deletedCount
}
}
8 changes: 7 additions & 1 deletion schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ type BatchDeleteModel {
deletedCount: Float
}

type BatchUpdateModel {
ok: Float
n: Float
nModified: Float
}

type BestAlbumModel {
_id: ID!
title: String!
Expand Down Expand Up @@ -104,7 +110,7 @@ type Mutation {
updatePlayerById(input: UpdatePlayerInput!): PlayerModel!
deletePlayerById(id: ID!): PlayerModel!
deletePlayer(ids: [ID!]!): BatchDeleteModel!
switchIsPubilc(ids: [ID!]!): PlayerModel!
switchIsPubilc(ids: [ID!]!): BatchUpdateModel!
}

type OpenSourceModel {
Expand Down
2 changes: 1 addition & 1 deletion src/announcements/announcements.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AnnouncementsService } from './announcements.service'
import { AnnouncementsModel } from './models/announcements.model'
import { CreateAnnouncementInput } from './dtos/create-announcement.input'
import { UpdateAnnouncementInput } from './dtos/update-announcement.input'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'

// const pubSub = new PubSub();

Expand Down
2 changes: 1 addition & 1 deletion src/best-albums/best-albums.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Args, Query, Resolver, Mutation } from '@nestjs/graphql'
import { ID } from 'type-graphql'
import { BestAlbumsService } from './best-albums.service'
import { BestAlbumModel } from './models/best-albums.model'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'
import { CreateBestAlbumInput } from './dtos/create-best-album.input'
import { UpdateBestAlbumInput } from './dtos/update-best-album.input'

Expand Down
2 changes: 1 addition & 1 deletion src/best-albums/best-albums.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CreateBestAlbumInput } from './dtos/create-best-album.input'
import { UpdateBestAlbumInput } from './dtos/update-best-album.input'
import { BestAlbumModel } from './models/best-albums.model'
import { BestAlbum } from './interfaces/best-albums.interface'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'

@Injectable()
export class BestAlbumsService {
Expand Down
5 changes: 0 additions & 5 deletions src/database/interfaces/batchDelete.interface.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/database/models/batch-update.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Field, ObjectType } from 'type-graphql'

@ObjectType()
export class BatchUpdateModel {
@Field({ nullable: true })
public readonly ok?: number

@Field({ nullable: true })
public readonly n?: number

@Field({ nullable: true })
public readonly nModified?: number
}
2 changes: 1 addition & 1 deletion src/live-tours/live-tours.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Args, Query, Resolver, Mutation } from '@nestjs/graphql'
import { ID } from 'type-graphql'
import { LiveToursService } from './live-tours.service'
import { LiveTourModel } from './models/live-tours.model'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'
import { CreateLiveTourInput } from './dtos/create-live-tour.input'
import { UpdateLiveTourInput } from './dtos/update-live-tour.input'

Expand Down
2 changes: 1 addition & 1 deletion src/live-tours/live-tours.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CreateLiveTourInput } from './dtos/create-live-tour.input'
import { UpdateLiveTourInput } from './dtos/update-live-tour.input'
import { LiveTourModel } from './models/live-tours.model'
import { LiveTour } from './interfaces/live-tours.interface'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'

@Injectable()
export class LiveToursService {
Expand Down
3 changes: 1 addition & 2 deletions src/mottos/mottos.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { AuthGuard } from '@nestjs/passport'
import { MottosService } from './mottos.service'
import { CreateMottoDto } from './dtos/createMotto.dto'
import { Motto } from './interfaces/motto.interface'
import { BatchDelete } from '../database/interfaces/batchDelete.interface'

@Controller('mottos')
export class MottosResolver {
Expand Down Expand Up @@ -54,7 +53,7 @@ export class MottosResolver {

@UseGuards(AuthGuard())
@Delete()
public deleteMottos(@Body('ids') ids: string[]): Promise<BatchDelete> {
public deleteMottos(@Body('ids') ids: string[]) {
return this.mottosService.batchDelete(ids)
}
}
3 changes: 1 addition & 2 deletions src/mottos/mottos.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { InjectModel } from '@nestjs/mongoose'
import { Injectable } from '@nestjs/common'
import { Motto } from './interfaces/motto.interface'
import { CreateMottoDto } from './dtos/createMotto.dto'
import { BatchDelete } from '../database/interfaces/batchDelete.interface'

@Injectable()
export class MottosService {
Expand Down Expand Up @@ -39,7 +38,7 @@ export class MottosService {
return res
}

public async batchDelete(ids: string[]): Promise<BatchDelete> {
public async batchDelete(ids: string[]) {
const res = await this.MottoModel.deleteMany({
_id: { $in: ids },
})
Expand Down
2 changes: 1 addition & 1 deletion src/open-sources/open-sources.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Args, Query, Resolver, Mutation } from '@nestjs/graphql'
import { ID } from 'type-graphql'
import { OpenSourcesService } from './open-sources.service'
import { OpenSourceModel } from './models/open-sources.model'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'
import { CreateOpenSourceInput } from './dtos/create-open-source.input'
import { UpdateOpenSourceInput } from './dtos/update-open-source.input'

Expand Down
2 changes: 1 addition & 1 deletion src/open-sources/open-sources.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CreateOpenSourceInput } from './dtos/create-open-source.input'
import { UpdateOpenSourceInput } from './dtos/update-open-source.input'
import { OpenSourceModel } from './models/open-sources.model'
import { OpenSource } from './interfaces/open-sources.interface'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'

@Injectable()
export class OpenSourcesService {
Expand Down
5 changes: 3 additions & 2 deletions src/player/player.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Args, Query, Resolver, Mutation } from '@nestjs/graphql'
import { ID } from 'type-graphql'
import { PlayerService } from './player.service'
import { PlayerModel } from './models/player.model'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'
import { BatchUpdateModel } from '../database/models/batch-update.model'
import { CreatePlayerInput } from './dtos/create-player.input'
import { UpdatePlayerInput } from './dtos/update-player.input'

Expand Down Expand Up @@ -42,7 +43,7 @@ export class PlayerResolver {
return this.playerService.batchDelete(ids)
}

@Mutation(() => null)
@Mutation(() => BatchUpdateModel)
public async switchIsPubilc(@Args({ name: 'ids', type: () => [ID] }) ids: string[]) {
return this.playerService.switchIsPubilc(ids)
}
Expand Down
2 changes: 1 addition & 1 deletion src/player/player.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CreatePlayerInput } from './dtos/create-player.input'
import { UpdatePlayerInput } from './dtos/update-player.input'
import { PlayerModel } from './models/player.model'
import { Player } from './interfaces/player.interface'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'

@Injectable()
export class PlayerService {
Expand Down
2 changes: 1 addition & 1 deletion src/yancey-music/yancey-music.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Args, Query, Resolver, Mutation } from '@nestjs/graphql'
import { ID } from 'type-graphql'
import { YanceyMusicService } from './yancey-music.service'
import { YanceyMusicModel } from './models/yancey-music.model'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'
import { CreateYanceyMusicInput } from './dtos/create-yancey-music.input'
import { UpdateYanceyMusicInput } from './dtos/update-yancey-music.input'

Expand Down
2 changes: 1 addition & 1 deletion src/yancey-music/yancey-music.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CreateYanceyMusicInput } from './dtos/create-yancey-music.input'
import { UpdateYanceyMusicInput } from './dtos/update-yancey-music.input'
import { YanceyMusicModel } from './models/yancey-music.model'
import { YanceyMusic } from './interfaces/yancey-music.interface'
import { BatchDeleteModel } from '../database/models/database.model'
import { BatchDeleteModel } from '../database/models/batch-delete.model'

@Injectable()
export class YanceyMusicService {
Expand Down
4 changes: 2 additions & 2 deletions test/announcements.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AnnouncementsModule } from '../src/announcements/announcements.module'
import { AnnouncementsModel } from '../src/announcements/models/announcements.model'
import { CreateAnnouncementInput } from '../src/announcements/dtos/create-announcement.input'
import { UpdateAnnouncementInput } from '../src/announcements/dtos/update-announcement.input'
import { BatchDelete } from '../src/database/interfaces/batchDelete.interface'
import { BatchDeleteModel } from '../src/database/models/batch-delete.model'

describe('AnnouncementsController (e2e)', () => {
let app: NestApplication
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('AnnouncementsController (e2e)', () => {
query: batchDeleteTypeDefs,
})
.expect(({ body }) => {
const testData: BatchDelete = body.data.deleteAnnouncements
const testData: BatchDeleteModel = body.data.deleteAnnouncements
expect(testData.ok).toBe(1)
expect(testData.n).toBe(0)
expect(testData.deletedCount).toBe(0)
Expand Down
4 changes: 2 additions & 2 deletions test/best-albums.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { BestAlbumsModule } from '../src/best-albums/best-albums.module'
import { BestAlbumModel } from '../src/best-albums/models/best-albums.model'
import { CreateBestAlbumInput } from '../src/best-albums/dtos/create-best-album.input'
import { UpdateBestAlbumInput } from '../src/best-albums/dtos/update-best-album.input'
import { BatchDelete } from '../src/database/interfaces/batchDelete.interface'
import { BatchDeleteModel } from '../src/database/models/batch-delete.model'

describe('BestAlbumsController (e2e)', () => {
let app: NestApplication
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('BestAlbumsController (e2e)', () => {
query: batchDeleteTypeDefs,
})
.expect(({ body }) => {
const testData: BatchDelete = body.data.deleteBestAlbums
const testData: BatchDeleteModel = body.data.deleteBestAlbums
expect(testData.ok).toBe(1)
expect(testData.n).toBe(0)
expect(testData.deletedCount).toBe(0)
Expand Down
4 changes: 2 additions & 2 deletions test/live-tours.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LiveToursModule } from '../src/live-tours/live-tours.module'
import { LiveTourModel } from '../src/live-tours/models/live-tours.model'
import { CreateLiveTourInput } from '../src/live-tours/dtos/create-live-tour.input'
import { UpdateLiveTourInput } from '../src/live-tours/dtos/update-live-tour.input'
import { BatchDelete } from '../src/database/interfaces/batchDelete.interface'
import { BatchDeleteModel } from '../src/database/models/batch-delete.model'

describe('LiveToursController (e2e)', () => {
let app: NestApplication
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('LiveToursController (e2e)', () => {
query: batchDeleteTypeDefs,
})
.expect(({ body }) => {
const testData: BatchDelete = body.data.deleteLiveTours
const testData: BatchDeleteModel = body.data.deleteLiveTours
expect(testData.ok).toBe(1)
expect(testData.n).toBe(0)
expect(testData.deletedCount).toBe(0)
Expand Down
4 changes: 2 additions & 2 deletions test/open-sources.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { OpenSourcesModule } from '../src/open-sources/open-sources.module'
import { OpenSourceModel } from '../src/open-sources/models/open-sources.model'
import { CreateOpenSourceInput } from '../src/open-sources/dtos/create-open-source.input'
import { UpdateOpenSourceInput } from '../src/open-sources/dtos/update-open-source.input'
import { BatchDelete } from '../src/database/interfaces/batchDelete.interface'
import { BatchDeleteModel } from '../src/database/models/batch-delete.model'

describe('OpenSourcesController (e2e)', () => {
let app: NestApplication
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('OpenSourcesController (e2e)', () => {
query: batchDeleteTypeDefs,
})
.expect(({ body }) => {
const testData: BatchDelete = body.data.deleteOpenSources
const testData: BatchDeleteModel = body.data.deleteOpenSources
expect(testData.ok).toBe(1)
expect(testData.n).toBe(0)
expect(testData.deletedCount).toBe(0)
Expand Down
4 changes: 2 additions & 2 deletions test/player.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PlayerModule } from '../src/player/player.module'
import { PlayerModel } from '../src/player/models/player.model'
import { CreatePlayerInput } from '../src/player/dtos/create-player.input'
import { UpdatePlayerInput } from '../src/player/dtos/update-player.input'
import { BatchDelete } from '../src/database/interfaces/batchDelete.interface'
import { BatchDeleteModel } from '../src/database/models/batch-delete.model'

describe('PlayerController (e2e)', () => {
let app: NestApplication
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('PlayerController (e2e)', () => {
query: batchDeleteTypeDefs,
})
.expect(({ body }) => {
const testData: BatchDelete = body.data.deletePlayer
const testData: BatchDeleteModel = body.data.deletePlayer
expect(testData.ok).toBe(1)
expect(testData.n).toBe(0)
expect(testData.deletedCount).toBe(0)
Expand Down
4 changes: 2 additions & 2 deletions test/yancey-music.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { YanceyMusicModule } from '../src/yancey-music/yancey-music.module'
import { YanceyMusicModel } from '../src/yancey-music/models/yancey-music.model'
import { CreateYanceyMusicInput } from '../src/yancey-music/dtos/create-yancey-music.input'
import { UpdateYanceyMusicInput } from '../src/yancey-music/dtos/update-yancey-music.input'
import { BatchDelete } from '../src/database/interfaces/batchDelete.interface'
import { BatchDeleteModel } from '../src/database/models/batch-delete.model'

describe('YanceyMusicController (e2e)', () => {
let app: NestApplication
Expand Down Expand Up @@ -242,7 +242,7 @@ describe('YanceyMusicController (e2e)', () => {
query: batchDeleteTypeDefs,
})
.expect(({ body }) => {
const testData: BatchDelete = body.data.deleteYanceyMusic
const testData: BatchDeleteModel = body.data.deleteYanceyMusic
expect(testData.ok).toBe(1)
expect(testData.n).toBe(0)
expect(testData.deletedCount).toBe(0)
Expand Down

0 comments on commit 6b422e8

Please sign in to comment.