notification v1

This commit is contained in:
Rotimi Best
2023-10-05 19:21:39 +01:00
parent 195ac54467
commit 2040257916
2 changed files with 45 additions and 0 deletions
@@ -0,0 +1,4 @@
1. Welcome new user into classroomio
2. Sends teacher welcome to course
3. Notify teacher someone wants to buy course
4
@@ -0,0 +1,41 @@
import { supabase } from '$lib/utils/functions/supabase';
export class Notification {
name = '';
accessToken = '';
constructor(name: string) {
this.name = name;
}
async getAccessToken() {
const { data } = await supabase.auth.getSession();
this.accessToken = data.session?.access_token || '';
return this.accessToken;
}
async send(path: string, body: { [k: string]: string }) {
try {
await this.getAccessToken();
const response = await fetch(path, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: this.accessToken
},
body: JSON.stringify(body)
});
if (!response.ok) {
throw new Error(await response.text());
}
const result = await response.json();
console.log(`${this.name} sent email result`, result);
} catch (error) {
console.log(`${this.name} sent email error`, error);
}
}
}
export class InviteNotification extends Notification {}