foods pagination

This commit is contained in:
2025-12-21 09:43:16 +03:30
parent d80199fc65
commit 37f7b11dbc
4 changed files with 39 additions and 92 deletions
@@ -25,6 +25,16 @@ export class ResponseInterceptor implements NestInterceptor {
return data; return data;
} }
// Check if this is a paginated result (has both data and meta properties)
if (data && typeof data === 'object' && 'data' in data && 'meta' in data) {
return {
statusCode,
success: true,
data: data.data,
meta: data.meta,
};
}
if (data && data.data !== undefined) { if (data && data.data !== undefined) {
return { return {
statusCode, statusCode,
@@ -88,8 +88,9 @@ export class FoodController {
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] }) @ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
@ApiQuery({ name: 'categoryId', required: false, type: String }) @ApiQuery({ name: 'categoryId', required: false, type: String })
@ApiQuery({ name: 'isActive', required: false, type: Boolean }) @ApiQuery({ name: 'isActive', required: false, type: Boolean })
findAll(@Query() dto: FindFoodsDto, @RestId() restId: string) { async findAll(@Query() dto: FindFoodsDto, @RestId() restId: string) {
return this.foodsService.findAll(restId, dto); const result =await this.foodsService.findAll(restId, dto);
return result;
} }
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@@ -62,5 +62,7 @@ export class FoodRepository extends EntityRepository<Food> {
totalPages, totalPages,
}, },
}; };
} }
} }
@@ -9,6 +9,7 @@ import { UserId } from 'src/common/decorators/user-id.decorator';
import { RestId } from 'src/common/decorators'; import { RestId } from 'src/common/decorators';
import { FindUsersDto } from '../dto/find-user.dto'; import { FindUsersDto } from '../dto/find-user.dto';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard'; import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { API_HEADER_SLUG } from 'src/common/constants/index';
@ApiTags('User') @ApiTags('User')
@Controller() @Controller()
@@ -18,14 +19,7 @@ export class UsersController {
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Get the current authenticated user profile' }) @ApiOperation({ summary: 'Get the current authenticated user profile' })
@ApiHeader({ @ApiHeader(API_HEADER_SLUG)
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@Get('public/user/me') @Get('public/user/me')
async getUser(@UserId() userId: string) { async getUser(@UserId() userId: string) {
const user = await this.userService.findById(userId); const user = await this.userService.findById(userId);
@@ -34,14 +28,7 @@ export class UsersController {
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Update the authenticated user profile' }) @ApiOperation({ summary: 'Update the authenticated user profile' })
@ApiHeader({ @ApiHeader(API_HEADER_SLUG)
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@ApiBody({ type: UpdateUserDto }) @ApiBody({ type: UpdateUserDto })
@Patch('public/user/update') @Patch('public/user/update')
async updateUser(@UserId() userId: string, @RestId() restId: string, @Body() dto: UpdateUserDto) { async updateUser(@UserId() userId: string, @RestId() restId: string, @Body() dto: UpdateUserDto) {
@@ -52,14 +39,7 @@ export class UsersController {
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Get all addresses for the authenticated user' }) @ApiOperation({ summary: 'Get all addresses for the authenticated user' })
@ApiHeader({ @ApiHeader(API_HEADER_SLUG)
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@ApiOkResponse({ description: 'List of user addresses' }) @ApiOkResponse({ description: 'List of user addresses' })
@Get('public/user/addresses') @Get('public/user/addresses')
async getUserAddresses(@UserId() userId: string) { async getUserAddresses(@UserId() userId: string) {
@@ -70,14 +50,7 @@ export class UsersController {
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Get User Wallet' }) @ApiOperation({ summary: 'Get User Wallet' })
@ApiHeader({ @ApiHeader(API_HEADER_SLUG)
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@Get('public/user/wallet') @Get('public/user/wallet')
async getUserWallet(@UserId() userId: string, @RestId() restId: string) { async getUserWallet(@UserId() userId: string, @RestId() restId: string) {
const wallet = await this.userService.getUserWallet(userId, restId); const wallet = await this.userService.getUserWallet(userId, restId);
@@ -87,14 +60,7 @@ export class UsersController {
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Create a new address for the authenticated user' }) @ApiOperation({ summary: 'Create a new address for the authenticated user' })
@ApiHeader({ @ApiHeader(API_HEADER_SLUG)
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@ApiBody({ type: CreateUserAddressDto }) @ApiBody({ type: CreateUserAddressDto })
@ApiOkResponse({ description: 'Created user address' }) @ApiOkResponse({ description: 'Created user address' })
@Post('public/user/addresses') @Post('public/user/addresses')
@@ -109,14 +75,7 @@ export class UsersController {
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Get a single address by ID for the authenticated user' }) @ApiOperation({ summary: 'Get a single address by ID for the authenticated user' })
@ApiHeader({ @ApiHeader(API_HEADER_SLUG)
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@ApiOkResponse({ description: 'User address details' }) @ApiOkResponse({ description: 'User address details' })
@Get('public/user/addresses/:addressId') @Get('public/user/addresses/:addressId')
async getUserAddress(@UserId() userId: string, @Param('addressId') addressId: string) { async getUserAddress(@UserId() userId: string, @Param('addressId') addressId: string) {
@@ -127,14 +86,7 @@ export class UsersController {
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Update an address for the authenticated user' }) @ApiOperation({ summary: 'Update an address for the authenticated user' })
@ApiHeader({ @ApiHeader(API_HEADER_SLUG)
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@ApiBody({ type: UpdateUserAddressDto }) @ApiBody({ type: UpdateUserAddressDto })
@ApiOkResponse({ description: 'Updated user address' }) @ApiOkResponse({ description: 'Updated user address' })
@Patch('public/user/addresses/:addressId') @Patch('public/user/addresses/:addressId')
@@ -150,14 +102,7 @@ export class UsersController {
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Delete an address for the authenticated user' }) @ApiOperation({ summary: 'Delete an address for the authenticated user' })
@ApiHeader({ @ApiHeader(API_HEADER_SLUG)
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@ApiOkResponse({ description: 'Address deleted successfully' }) @ApiOkResponse({ description: 'Address deleted successfully' })
@Delete('public/user/addresses/:addressId') @Delete('public/user/addresses/:addressId')
async deleteUserAddress(@UserId() userId: string, @Param('addressId') addressId: string) { async deleteUserAddress(@UserId() userId: string, @Param('addressId') addressId: string) {
@@ -168,14 +113,7 @@ export class UsersController {
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Set an address as default for the authenticated user' }) @ApiOperation({ summary: 'Set an address as default for the authenticated user' })
@ApiHeader({ @ApiHeader(API_HEADER_SLUG)
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@ApiOkResponse({ description: 'Address set as default' }) @ApiOkResponse({ description: 'Address set as default' })
@Patch('public/user/addresses/:addressId/default') @Patch('public/user/addresses/:addressId/default')
async setDefaultAddress(@UserId() userId: string, @Param('addressId') addressId: string) { async setDefaultAddress(@UserId() userId: string, @Param('addressId') addressId: string) {
@@ -183,6 +121,19 @@ export class UsersController {
return address; return address;
} }
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Convert user score (points) to wallet balance' })
@ApiHeader(API_HEADER_SLUG)
@Post('public/user/convert-score-to-wallet')
async convertScoreToWallet(@UserId() userId: string, @RestId() restId: string) {
await this.userService.convertScoreToWallet(userId, restId);
return {
message: 'Score converted to wallet successfully',
};
}
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@ApiOperation({ summary: 'Get paginated list of restuarant users with filters' }) @ApiOperation({ summary: 'Get paginated list of restuarant users with filters' })
@@ -196,22 +147,5 @@ export class UsersController {
return this.userService.findAll(restId, query); return this.userService.findAll(restId, query);
} }
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Convert user score (points) to wallet balance' })
@ApiHeader({
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@Post('public/user/convert-score-to-wallet')
async convertScoreToWallet(@UserId() userId: string, @RestId() restId: string) {
await this.userService.convertScoreToWallet(userId, restId);
return {
message: 'Score converted to wallet successfully',
};
}
} }