Skip to content

Commit

Permalink
Added user destroy method
Browse files Browse the repository at this point in the history
  • Loading branch information
bashleigh committed Oct 12, 2018
1 parent ee89dd7 commit 5c15599
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { Pagination } from '../paginate';
import { INestApplication } from '@nestjs/common';
import { UserEntity } from '../entities';
import { UpdateResult } from 'typeorm';
import { UpdateResult, DeleteResult } from 'typeorm';

describe('UserService', () => {
let module: TestingModule;
Expand Down Expand Up @@ -87,5 +87,10 @@ describe('UserService', () => {
expect(result).toEqual(expect.objectContaining(user));
});

afterAll(() => app.close());
it('delete', async () => {
const result = await userService.destroy(user.id);
expect(result).toBeInstanceOf(DeleteResult);
});

afterAll(async () => app.close());
});
6 changes: 5 additions & 1 deletion src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, UpdateResult } from 'typeorm';
import { Repository, UpdateResult, DeleteResult } from 'typeorm';
import { UserEntity as User, UserEntity } from './../entities';
import { Pagination, PaginationOptionsInterface } from './../paginate';
import { UserModel } from 'models';
Expand Down Expand Up @@ -79,4 +79,8 @@ export class UserService {
},
);
}

async destroy(id: number): Promise<DeleteResult> {
return await this.userRepository.delete(id);
}
}

0 comments on commit 5c15599

Please sign in to comment.