-
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.
- Loading branch information
Showing
8 changed files
with
99 additions
and
50 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 |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import { createApiClient } from '@accentor/api-client-js' | ||
import type { App } from 'vue' | ||
|
||
export default { | ||
install: (app: App) => { | ||
let url: string | ||
if (import.meta.env.VITE_APP_API_URL != undefined) { | ||
url = import.meta.env.VITE_APP_API_URL | ||
} else if (import.meta.env.PROD) { | ||
url = '/api' | ||
} else { | ||
url = 'http://localhost:3000/api' | ||
} | ||
app.provide('apiBaseUrl', url) | ||
app.provide('api', createApiClient(url)) | ||
} | ||
let url: string | ||
if (import.meta.env.VITE_APP_API_URL != undefined) { | ||
url = import.meta.env.VITE_APP_API_URL | ||
} else if (import.meta.env.PROD) { | ||
url = '/api' | ||
} else { | ||
url = 'http://localhost:3000/api' | ||
} | ||
|
||
export const baseURL = url | ||
|
||
export default createApiClient(url) |
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,41 @@ | ||
import type SqliteClient from '@/db-client' | ||
import api from '@/api' | ||
import { useAuthStore } from '@/stores/auth' | ||
import type { UnwrapNestedRefs } from 'vue' | ||
|
||
export default class UserDao { | ||
client: SqliteClient | ||
authStore: UnwrapNestedRefs<{ secret: string | null; deviceId: string | null }> | ||
|
||
constructor(client: SqliteClient) { | ||
this.client = client | ||
this.authStore = useAuthStore() | ||
} | ||
|
||
async refresh() { | ||
let done = false | ||
const generator = api.users.index({ | ||
secret: this.authStore.secret!, | ||
device_id: this.authStore.deviceId! | ||
}) | ||
while (!done) { | ||
const obj = await generator.next() | ||
for (const row of obj.value) { | ||
await this.client.executeMutation( | ||
'users', | ||
'INSERT INTO users VALUES (?, ?, ?) ON CONFLICT(id) DO UPDATE SET name=?, permission=?;', | ||
row.id, | ||
row.name, | ||
row.permission, | ||
row.name, | ||
row.permission | ||
) | ||
} | ||
done = obj.done! | ||
} | ||
} | ||
|
||
getAll() { | ||
return this.client.executeSelect(['users'], 'SELECT * FROM users;') | ||
} | ||
} |
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
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