TypeORM storage for Notification System
npm install @node-notifications/storage-typeorm-0.3TypeORM v0.3 storage for Notification System
> yarn add @node-notifications/storage-typeorm-0.3
- Copy migrations from library to project migrations directory
```
cp ./node_modules/@node-notifications/storage-typeorm-0.3/migrations/*.js ./migrations/
- Run migrations
``
./node_modules/.bin/typeorm migration:run
- Revert migrations
``
./node_modules/.bin/typeorm migration:revert
`typescript
import { ConsoleTransport, NotificationQueueManager, NotificationService } from '@node-notifications/core';
import { TypeormStorage } from '@node-notifications/storage-typeorm-0.3';
let service: NotificationService;
let queueManager: NotificationQueueManager;
async function main() {
// Instantiate Notification Service
service = new NotificationService(
// eslint-disable-next-line @typescript-eslint/no-var-requires
await new TypeormStorage().initialize(require('./ormconfig.js')),
{
// Log all notification to console (for test/demo purpose)
console: new ConsoleTransport(),
},
);
// Instantiate Notification Queue Manager and start Queue Processing
queueManager = new NotificationQueueManager(service).start();
// To stop Queue Processing:
// queueManager.stop();
// ...
// Sample usage (data: INotification)
service.send({ recipient: 'user@mail.test', payload: 'Test Notification', transports: ['console'] }).then();
}
``