Skip to content
Open
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
12 changes: 5 additions & 7 deletions apps/sample/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Controller, Get, UseGuards } from '@nestjs/common';
import { Controller, Get } from '@nestjs/common';

import { ApiTags } from '@nestjs/swagger';
import { AppService } from './app.service';
import { AbilitiesGuard, CheckAbilities, JwtGuard } from '@rumsan/user';
import { ACTIONS, APP, SUBJECTS } from '../constants';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';

@Controller('app')
@ApiTags('App')
@ApiBearerAuth(APP.JWT_BEARER)
//@ApiBearerAuth(APP.JWT_BEARER)
export class AppController {
constructor(private readonly appService: AppService) {}

@CheckAbilities({ action: ACTIONS.READ, subject: SUBJECTS.USER })
@UseGuards(JwtGuard, AbilitiesGuard)
// @CheckAbilities({ action: ACTIONS.READ, subject: SUBJECTS.USER })
// @UseGuards(JwtGuard, AbilitiesGuard)
@Get()
getData() {
return this.appService.getData();
Expand Down
25 changes: 22 additions & 3 deletions apps/sample/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,42 @@ import { Module } from '@nestjs/common';
// import { UserModule } from '../user/user.module';
import { PrismaModule } from '@rumsan/prisma';

import { ConfigModule } from '@nestjs/config';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { RumsanUserModule } from '@rumsan/user';
import { QueueModule } from '@rumsan/queue';
import { RumsanUserModule, SignupModule } from '@rumsan/user';
import { ListenerModule } from '../listener/listener.module';
import { UserModule } from '../user/user.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';
// bullmq.transport.ts

@Module({
imports: [
QueueModule.forRoot({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
connection: {
host: configService.get<string>('REDIS_HOST'),
port: +configService.get<number>('REDIS_PORT'),
password: configService.get<string>('REDIS_PASSWORD'),
// retryStrategy: (times) => {
// // reconnect after
// return Math.min(times * 50, 2000);
// },
// // might need to change on producttion
// maxRetriesPerRequest: 1000,
},
}),
inject: [ConfigService],
}),
ConfigModule.forRoot({ isGlobal: true }),
EventEmitterModule.forRoot({ maxListeners: 10, ignoreErrors: false }),
ListenerModule,
PrismaModule,
UserModule,
RumsanUserModule,
//SignupModule.register({ autoApprove: false }),
SignupModule.register({ autoApprove: false }),
],
controllers: [AppController],
providers: [AppService],
Expand Down
3 changes: 2 additions & 1 deletion apps/sample/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PrismaService } from '@rumsan/prisma';
import { Injectable } from '@nestjs/common';
import { PrismaService } from '@rumsan/prisma';

@Injectable()
export class AppService {
constructor(private prisma: PrismaService) {}
async getData() {
const d = await this.prisma.user.findMany();
// this.queue.sendMessage('APP_QUEUE', { message: 'Hello Santosh', data: d });
return { message: 'Hello API', data: d };
}
}
17 changes: 14 additions & 3 deletions apps/sample/src/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { Module } from '@nestjs/common';
import { RumsanUserModule } from '@rumsan/user';
import { PrismaModule } from '@rumsan/prisma';
import { QueueModule, QueueService } from '@rumsan/queue';
import { AuthModule } from '@rumsan/user';
import { AppUserController } from './user.controller';
import { UserProcessor } from './user.processor';
import { AppUserService } from './user.service';

@Module({
imports: [
AuthModule,
PrismaModule,
//QueueModule,
QueueModule.registerQueue({
name: 'APP_QUEUE',
}),
],
controllers: [AppUserController],
providers: [AppUserService],
providers: [UserProcessor, AppUserService, QueueService],
})
export class UserModule extends RumsanUserModule {}
export class UserModule {}
14 changes: 14 additions & 0 deletions apps/sample/src/user/user.processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable, Logger } from '@nestjs/common';

@Injectable()
export class UserProcessor {
private readonly _logger = new Logger('USER_TEST');

// constructor(@Inject('TRANSPORT') private readonly queue: QueueService) {}

// public async sendOTP(d): Promise<void> {
// this.queue.receiveMessage('USER_TEST', (data) => {
// console.log('data', data);
// });
// }
}
30 changes: 26 additions & 4 deletions apps/sample/src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { Injectable } from '@nestjs/common';
import { UserService } from '@rumsan/user';

const USER_ROLE_ID = 3;
import { PrismaService } from '@rumsan/prisma';
import { QueueService } from '@rumsan/queue';
import { AuthService, UserService } from '@rumsan/user';

@Injectable()
export class AppUserService extends UserService {
constructor(
protected prisma: PrismaService,
public authService: AuthService,
private queueService: QueueService,
) {
super(prisma, authService);
}

// @OnMessage()
async Test(dto: any) {
return {};
// console.log('queueService', { s: this.queueService });
this.queueService.sendMessage('APP_QUEUE', {
message: 'another santosh',
data: {
name: 'test',
},
});
// this.queueService.receiveMessage('QUEUE_TEST', (data: Job<any>) => {
// console.log('data', data);
// console.log(data.getState());
// return data;
// });

return { message: 'success' };
}
}
18 changes: 18 additions & 0 deletions libs/beneficiary/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/beneficiary/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# beneficiary

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test beneficiary` to execute the unit tests via [Jest](https://jestjs.io).
11 changes: 11 additions & 0 deletions libs/beneficiary/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'beneficiary',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/beneficiary',
};
20 changes: 20 additions & 0 deletions libs/beneficiary/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "beneficiary",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/beneficiary/src",
"projectType": "library",
"targets": {
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/beneficiary/jest.config.ts"
}
}
},
"tags": []
}
1 change: 1 addition & 0 deletions libs/beneficiary/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/beneficiary.module';
10 changes: 10 additions & 0 deletions libs/beneficiary/src/lib/beneficiary.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { PrismaModule, PrismaService } from '@rumsan/prisma';

@Module({
controllers: [],
providers: [PrismaService],
exports: [],
imports: [PrismaModule],
})
export class BeneficiaryModule {}
22 changes: 22 additions & 0 deletions libs/beneficiary/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
16 changes: 16 additions & 0 deletions libs/beneficiary/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"],
"target": "es2021",
"strictNullChecks": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
14 changes: 14 additions & 0 deletions libs/beneficiary/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
18 changes: 18 additions & 0 deletions libs/queue/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
64 changes: 64 additions & 0 deletions libs/queue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## Queue Library Documentation

The Queue library is a module that provides a way to handle message queues in your application. It uses the BullMQ library as the default transport layer for sending and receiving messages, but you can also implement your own transport layer.

Setup
First, import the QueueModule in your application module:

```ts
import { QueueModule } from 'libs/queue/src/lib/queue.module';
```

# Configuration

The QueueModule accepts a configuration object of type IQueueModuleOptions from queue-config.interfaces.ts. This configuration object includes the queue configuration and transport layer.

Here is an example of how to use the forRoot method to configure the QueueModule:

```ts
@Module({
imports: [
QueueModule.forRoot({
config: {
queueName: 'myQueue',
// other BullMQ options...
},
transport: new BullMQTransport(/* transport options... */),
}),
],
})
export class AppModule {}
```

In this example, myQueue is the name of the queue, and BullMQTransport is the transport layer. You can replace BullMQTransport with your own transport layer if you want.

# Queue Library

This library provides a way to handle message queues in your application. It uses the BullMQ library as the default transport layer for sending and receiving messages, but you can also implement your own transport layer.

## Queue Service

The QueueService provides methods to interact with the queue. You can inject it into your services or controllers:

Here are the methods provided by the QueueService:

- `connect()`: Connects to the queue.
- `disconnect()`: Disconnects from the queue.
- `sendMessage(queue: string, data: any)`: Sends a message to the specified queue.
- `receiveMessage(queue: string, callback: (data: any) => void)`: Receives a message from the specified queue and processes it with the provided callback function.

## Queue Plugins

You can create custom plugins to modify the behavior of the queue. A plugin must implement the QueuePlugin interface from queue-plugin.interface.ts. The DefaultQueuePluginService from default-queue-plugin.service.ts is an example of a queue plugin.

## Transports

The transport layer is responsible for the actual sending and receiving of messages. The default transport is BullMQTransport from bull.transport.ts, but you can create your own by implementing the TransportInterface from transport.interface.ts.

## Testing

To run tests for the queue library, use the test script in the project.json file:

```sh
npm run test
```
11 changes: 11 additions & 0 deletions libs/queue/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'queue',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/queue',
};
Loading