Add notifications feature and update feature flags

This update includes creating new files for the notifications feature along with adding two feature flags for enabling notifications and realtime notifications. All the code and package dependencies required for the notifications functionality have been added. The 'pnpm-lock.yaml' has also been updated due to the inclusion of new package dependencies.
This commit is contained in:
giancarlo
2024-04-29 18:12:30 +07:00
parent b78e716298
commit 820ed1f56b
22 changed files with 9857 additions and 10538 deletions

View File

@@ -0,0 +1,53 @@
/**
* @file API for notifications
*
* Usage
*
* ```typescript
* import { createNotificationsApi } from '@kit/notifications/api';
*
* const api = createNotificationsApi(client);
*
* await api.createNotification({
* body: 'Hello, world!',
* account_id: '123',
* type: 'info',
* });
* ```
*
*/
import { SupabaseClient } from '@supabase/supabase-js';
import { Database } from '@kit/supabase/database';
import { createNotificationsService } from './notifications.service';
type Notification = Database['public']['Tables']['notifications'];
/**
* @name createNotificationsApi
* @param client
*/
export function createNotificationsApi(client: SupabaseClient<Database>) {
return new NotificationsApi(client);
}
/**
* @name NotificationsApi
*/
class NotificationsApi {
private readonly service: ReturnType<typeof createNotificationsService>;
constructor(private readonly client: SupabaseClient<Database>) {
this.service = createNotificationsService(client);
}
/**
* @name createNotification
* @description Create a new notification in the database
* @param params
*/
createNotification(params: Notification['Insert']) {
return this.service.createNotification(params);
}
}

View File

@@ -0,0 +1,23 @@
import 'server-only';
import { SupabaseClient } from '@supabase/supabase-js';
import { Database } from '@kit/supabase/database';
type Notification = Database['public']['Tables']['notifications'];
export function createNotificationsService(client: SupabaseClient<Database>) {
return new NotificationsService(client);
}
class NotificationsService {
constructor(private readonly client: SupabaseClient<Database>) {}
async createNotification(params: Notification['Insert']) {
const { error } = await this.client.from('notifications').insert(params);
if (error) {
throw error;
}
}
}