-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add header notification on user side and refactor admin side
- Loading branch information
1 parent
e15ff47
commit 7511e86
Showing
7 changed files
with
183 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
apps/e-commerce/src/user/header-notification/notification.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
Controller, | ||
Get, | ||
HttpCode, | ||
HttpStatus, | ||
UseInterceptors, | ||
} from '@nestjs/common'; | ||
import { JsonResponseTransformInterceptor } from '@rahino/response/interceptor'; | ||
import { ApiOperation, ApiTags } from '@nestjs/swagger'; | ||
import { HeaderNotificationService } from './notification.service'; | ||
|
||
@ApiTags('Admin-HeaderNotifications') | ||
@Controller({ | ||
path: '/api/ecommerce/user/headerNotifications', | ||
version: ['1'], | ||
}) | ||
export class HeaderNotificationController { | ||
constructor(private service: HeaderNotificationService) {} | ||
|
||
@UseInterceptors(JsonResponseTransformInterceptor) | ||
@ApiOperation({ description: 'get header notification' }) | ||
@Get('/') | ||
@HttpCode(HttpStatus.OK) | ||
async findOne() { | ||
return await this.service.findOne(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
apps/e-commerce/src/user/header-notification/notification.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; | ||
import { HeaderNotificationController } from './notification.controller'; | ||
import { HeaderNotificationService } from './notification.service'; | ||
import { SequelizeModule } from '@nestjs/sequelize'; | ||
import { Setting } from '@rahino/database/models/core/setting.entity'; | ||
|
||
@Module({ | ||
imports: [SequelizeModule.forFeature([Setting])], | ||
controllers: [HeaderNotificationController], | ||
providers: [HeaderNotificationService], | ||
}) | ||
export class UserHeaderNotificationModule implements NestModule { | ||
configure(consumer: MiddlewareConsumer) {} | ||
} |
46 changes: 46 additions & 0 deletions
46
apps/e-commerce/src/user/header-notification/notification.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/sequelize'; | ||
import { QueryOptionsBuilder } from '@rahino/query-filter/sequelize-query-builder'; | ||
import * as _ from 'lodash'; | ||
import { Setting } from '@rahino/database/models/core/setting.entity'; | ||
|
||
@Injectable() | ||
export class HeaderNotificationService { | ||
private readonly HEADER_NOTIFICATION_TEXT = 'HEADER_NOTIFICATION_TEXT'; | ||
private readonly HEADER_NOTIFICATION_TEXT_COLOR = | ||
'HEADER_NOTIFICATION_TEXT_COLOR'; | ||
private readonly HEADER_NOTIFICATION_BACKGROUND_COLOR = | ||
'HEADER_NOTIFICATION_BACKGROUND_COLOR'; | ||
constructor(@InjectModel(Setting) private repository: typeof Setting) {} | ||
|
||
async findOne() { | ||
const notificationText = await this.repository.findOne( | ||
new QueryOptionsBuilder() | ||
.filter({ | ||
key: this.HEADER_NOTIFICATION_TEXT, | ||
}) | ||
.build(), | ||
); | ||
const notificationTextColor = await this.repository.findOne( | ||
new QueryOptionsBuilder() | ||
.filter({ | ||
key: this.HEADER_NOTIFICATION_TEXT_COLOR, | ||
}) | ||
.build(), | ||
); | ||
const notificationBackgroundColor = await this.repository.findOne( | ||
new QueryOptionsBuilder() | ||
.filter({ | ||
key: this.HEADER_NOTIFICATION_BACKGROUND_COLOR, | ||
}) | ||
.build(), | ||
); | ||
return { | ||
result: { | ||
message: notificationText.value, | ||
textColor: notificationTextColor.value, | ||
backgroundColor: notificationBackgroundColor.value, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters