Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { PlainLiteralObject, SetMetadata } from '@nestjs/common';
import {
applyDecorators,
PlainLiteralObject,
SetMetadata,
} from '@nestjs/common';

import { CRUD_MODULE_ROUTE_VALIDATION_METADATA } from '../../../crud.constants';
import { CrudValidationOptions } from '../../../crud.types';
Expand All @@ -19,4 +23,5 @@ import { CrudValidationOptions } from '../../../crud.types';
*/
export const CrudValidate = <T extends PlainLiteralObject = PlainLiteralObject>(
options?: CrudValidationOptions<T>,
) => SetMetadata(CRUD_MODULE_ROUTE_VALIDATION_METADATA, options);
) =>
applyDecorators(SetMetadata(CRUD_MODULE_ROUTE_VALIDATION_METADATA, options));
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ describe.each([
.get('/photo?limit=10')
.expect(200);

expect(response.body).toBeInstanceOf(Array);
expect(response.body.length).toEqual(10);

expect(response.body).toBeInstanceOf(Object);
expect(response.body.data).toBeInstanceOf(Object);
expect(response.body.data).toBeInstanceOf(Array);
expect(response.body.data.length).toEqual(10);
});

it('GET /photo?limit=10&page=1', async () => {
Expand Down
12 changes: 10 additions & 2 deletions packages/nestjs-crud/src/util/configurable-crud.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ export class ConfigurableCrudBuilder<
),
);
CrudRequest()(InternalCrudClass.prototype, 'createOne', 0);
CrudBody()(InternalCrudClass.prototype, 'createOne', 1);
CrudBody({ validation: { expectedType: options.createOne?.dto } })(
InternalCrudClass.prototype,
'createOne',
1,
);
}

if (options?.updateOne) {
Expand All @@ -308,7 +312,11 @@ export class ConfigurableCrudBuilder<
),
);
CrudRequest()(InternalCrudClass.prototype, 'updateOne', 0);
CrudBody()(InternalCrudClass.prototype, 'updateOne', 1);
CrudBody({ validation: { expectedType: options.updateOne?.dto } })(
InternalCrudClass.prototype,
'updateOne',
1,
);
}

if (options?.replaceOne) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IntersectionType, PickType } from '@nestjs/swagger';
import { IntersectionType, PartialType, PickType } from '@nestjs/swagger';

import { OrgProfileUpdateDto } from '../../dto/profile/org-profile-update.dto';

import { OrgProfileDtoFixture } from './org-profile.dto.fixture';

export class OrgProfileUpdateDtoFixture extends IntersectionType(
OrgProfileUpdateDto,
PickType(OrgProfileDtoFixture, ['name'] as const),
PartialType(PickType(OrgProfileDtoFixture, ['name'] as const)),
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('Org Profile Crud Builder (e2e)', () => {

await supertest(app.getHttpServer())
.post('/org-profile')
.send({ orgId: org.id })
.send({ orgId: org.id, name: 'My Org' })
.expect(201);
});

Expand All @@ -178,7 +178,7 @@ describe('Org Profile Crud Builder (e2e)', () => {
// create org profile first
const createResponse = await supertest(app.getHttpServer())
.post('/org-profile')
.send({ orgId: org.id })
.send({ orgId: org.id, name: 'My Org Updated' })
.expect(201);

const id = createResponse.body.id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IntersectionType, PickType } from '@nestjs/swagger';
import { IntersectionType, PartialType, PickType } from '@nestjs/swagger';

import { UserProfileUpdateDto } from '../../dto/profile/user-profile-update.dto';

import { UserProfileDtoFixture } from './user-profile.dto.fixture';

export class UserProfileUpdateDtoFixture extends IntersectionType(
UserProfileUpdateDto,
PickType(UserProfileDtoFixture, ['firstName'] as const),
PartialType(PickType(UserProfileDtoFixture, ['firstName'] as const)),
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('User Profile Crud Builder (e2e)', () => {

await supertest(app.getHttpServer())
.post('/user-profile')
.send({ userId: user.id })
.send({ userId: user.id, firstName: 'Foo' })
.expect(201);
});

Expand All @@ -89,7 +89,7 @@ describe('User Profile Crud Builder (e2e)', () => {
// create user profile first
const createResponse = await supertest(app.getHttpServer())
.post('/user-profile')
.send({ userId: user.id })
.send({ userId: user.id, firstName: 'Bar' })
.expect(201);

const id = createResponse.body.id;
Expand Down