Skip to content

Commit

Permalink
feat: get services from slangroom and put the data in to qrcode
Browse files Browse the repository at this point in the history
  • Loading branch information
phoebus-84 committed Jan 29, 2024
1 parent e857c94 commit 8aca1a2
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 74 deletions.
75 changes: 75 additions & 0 deletions src/lib/slangroom/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { PUBLIC_BACKEND_URL } from '$env/static/public';
//@ts-ignore
import { Slangroom } from '@slangroom/core';
//@ts-ignore
import { http } from '@slangroom/http';

const slangroom = new Slangroom(http);

export type PaginatedResult<T> = {
page: number;
perPage: number;
totalItems: number;
totalPages: number;
items: T[];
};

export type Response<T> = {
result: T;
status: number;
};

export type Service = {
add_ons: boolean;
collectionId: string;
collectionName: string;
created: string;
id: string;
issuer: string;
name: string;
organization: string;
published: boolean;
templates: string[];
updated: string;
};

export const getServices = async (): Promise<Response<PaginatedResult<Service>>> => {
try {
const res = await slangroom.execute(
`Rule unknown ignore
Given I connect to 'path' and do get and output into 'http_result'
Given I have a 'string dictionary' named 'http_result'
Then print data
`,
{
data: {
path: `${PUBLIC_BACKEND_URL}/api/collections/services/records?expand=issuer&sort=-updated&filter=(organization='6snnqkixx6eszue')`
}
}
);
return res.result.http_result;
} catch (e: any) {
console.log(e);
throw new Error(JSON.stringify(e));
}
};

export const getService = async (id: string): Promise<any> => {
try {
const res = await slangroom.execute(
`Rule unknown ignore
Given I connect to 'path' and do get and output into 'http_result'
Given I have a 'string dictionary' named 'http_result'
Then print data`,
{
data: { path: `${PUBLIC_BACKEND_URL}/api/collections/services/records/${id}?expand=templates` }
}
);
return res.result.http_result.result;
} catch (e: any) {
console.log(e);
throw new Error(e);
}
};
84 changes: 14 additions & 70 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,9 @@
import Logo from '$lib/components/atoms/Logo.svelte';
import Card from '$lib/components/molecules/Card.svelte';
import fakeCredentials from '$lib/fakeCredentials';
//
// import {
// PushNotifications,
// type DeliveredNotifications,
// type PushNotificationSchema
// } from '@capacitor/push-notifications';
import { getServices } from '$lib/slangroom/services';
// let incomingNotification: PushNotificationSchema;
// let registrationToken: string;
// let notificationsList: DeliveredNotifications;
// const addListeners = async () => {
// await PushNotifications.addListener('registration', (token) => {
// registrationToken = token.value;
// console.info('Registration token: ', token.value);
// });
// await PushNotifications.addListener('registrationError', (err) => {
// registrationToken = err.error;
// console.error('Registration error: ', err.error);
// });
// await PushNotifications.addListener('pushNotificationReceived', (notification) => {
// incomingNotification = notification;
// console.log('Push notification received: ', notification);
// });
// await PushNotifications.addListener('pushNotificationActionPerformed', (notification) => {
// console.log('Push notification action performed', notification.actionId, notification.inputValue);
// });
// };
// const registerNotifications = async () => {
// let permStatus = await PushNotifications.checkPermissions();
// if (permStatus.receive === 'prompt') {
// permStatus = await PushNotifications.requestPermissions();
// }
// if (permStatus.receive !== 'granted') {
// throw new Error('User denied permissions!');
// }
// await PushNotifications.register();
// };
// const getDeliveredNotifications = async () => {
// const notificationList = await PushNotifications.getDeliveredNotifications();
// console.log('delivered notifications', notificationList);
// };
// registerNotifications();
// addListeners();
// $: getDeliveredNotifications();
</script>

<ion-header>
Expand All @@ -71,23 +20,18 @@

<ion-content fullscreen class="ion-padding space-y-10">
<h1 class="text-[32px] font-medium leading-[20.5px] tracking-[-0.5px] text-[#E8D2FF]">Home</h1>
{#each fakeCredentials as credential}
<Card title={credential.title} content={credential.issuedBy}>
<ion-button href={`/verify/`}>Verify</ion-button>
</Card>
{/each}
{#await getServices()}
<ion-spinner />
{:then res}
{@const services = res.result.items}
<div class="flex flex-col gap-2">
{#each services as service}
<d-credential-service name={service.name} issuer={service.issuer} href={`/verify/${service.id}`} />
{/each}
</div>
{/await}
<br />
<!-- {#if registrationToken}
<ion-Input value={registrationToken} label="registration token" />
{/if}
{#if incomingNotification}
<pre>
{JSON.stringify(incomingNotification, null, 2)}
</pre>
{/if}
{#if notificationsList}
<pre>
{JSON.stringify(notificationsList, null, 2)}
</pre>
{/if} -->

</ion-content>


Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { onMount } from 'svelte';
import { thumbsDownOutline, thumbsUpOutline } from 'ionicons/icons';
export let data:any
let qr: any;
let error: string;
let tok: string;
Expand All @@ -27,8 +29,8 @@ Then print data
tok = token.value;
const text = JSON.stringify({
url: 'http://192.168.1.36:3000/verify-credential',
name: 'over18',
issuedBy: 'ItGov',
name: data.credential.name,
issuedBy: data.credential.issuer,
registrationToken: token.value
});
qr = await slangroom.execute(scriptCreate, {
Expand Down Expand Up @@ -89,6 +91,4 @@ Then print data
<img src={qr.result.qrcode} alt="qrCode" class="w-full pt-20" />
{/if}
</div>
<!-- {JSON.stringify(incomingNotification)} -->
<!-- <ion-input value={tok}></ion-input> -->
</ion-content>
6 changes: 6 additions & 0 deletions src/routes/verify/[id]/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { getService } from '$lib/slangroom/services.js';

export const load = async ({ params }) => {
const credential = await getService(params.id);
return { credential };
};

0 comments on commit 8aca1a2

Please sign in to comment.