-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get services from slangroom and put the data in to qrcode
- Loading branch information
1 parent
e857c94
commit 8aca1a2
Showing
4 changed files
with
99 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}; |