mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 19:24:53 +00:00
feat: Add User Notification and Device Messages Subscription Modules
This commit is contained in:
1
src/user-notification/controllers/index.ts
Normal file
1
src/user-notification/controllers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './user-notification.controller';
|
||||
@ -0,0 +1,94 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { UserNotificationService } from '../services/user-notification.service';
|
||||
import {
|
||||
UserNotificationAddDto,
|
||||
UserNotificationUpdateDto,
|
||||
} from '../dtos/user-notification.dto';
|
||||
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
|
||||
@ApiTags('User Notification Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: 'user-notification/subscription',
|
||||
})
|
||||
export class UserNotificationController {
|
||||
constructor(
|
||||
private readonly userNotificationService: UserNotificationService,
|
||||
) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post()
|
||||
async addUserSubscription(
|
||||
@Body() userNotificationAddDto: UserNotificationAddDto,
|
||||
) {
|
||||
try {
|
||||
const addDetails = await this.userNotificationService.addUserSubscription(
|
||||
userNotificationAddDto,
|
||||
);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
message: 'User Notification Added Successfully',
|
||||
data: addDetails,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':userUuid')
|
||||
async fetchUserSubscriptions(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
const userDetails =
|
||||
await this.userNotificationService.fetchUserSubscriptions(userUuid);
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'User Notification fetched Successfully',
|
||||
data: { ...userDetails },
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put()
|
||||
async updateUserSubscription(
|
||||
@Body() userNotificationUpdateDto: UserNotificationUpdateDto,
|
||||
) {
|
||||
try {
|
||||
await this.userNotificationService.updateUserSubscription(
|
||||
userNotificationUpdateDto,
|
||||
);
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'User subscription updated Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user