initial commit
This commit is contained in:
11
app/repositories/factory.ts
Normal file
11
app/repositories/factory.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { $Fetch, SearchParameters } from 'ofetch';
|
||||
|
||||
export async function fetchWithRepo<T>(
|
||||
fetcher: $Fetch,
|
||||
url: string,
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE' = 'GET',
|
||||
body?: any,
|
||||
params?: SearchParameters
|
||||
): Promise<T> {
|
||||
return await fetcher(url, { method, body, params });
|
||||
}
|
||||
22
app/repositories/lists.repository.ts
Normal file
22
app/repositories/lists.repository.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { $Fetch } from 'ofetch';
|
||||
import type { List } from '~/types/lists'
|
||||
|
||||
export default class ListRepository {
|
||||
private fetcher: $Fetch;
|
||||
|
||||
constructor(fetcher: $Fetch) {
|
||||
this.fetcher = fetcher;
|
||||
}
|
||||
|
||||
async getAll() {
|
||||
return await this.fetcher<List[]>('/lists');
|
||||
}
|
||||
|
||||
async create(data: Partial<List>) {
|
||||
return await this.fetcher<List>('/lists', {
|
||||
method: 'POST',
|
||||
body: data
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
63
app/repositories/user.repository.ts
Normal file
63
app/repositories/user.repository.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import type { $Fetch } from 'ofetch';
|
||||
import type { User, ConfirmResult } from '~/types/auth'
|
||||
|
||||
export default class UserRepository {
|
||||
private fetcher: $Fetch;
|
||||
|
||||
constructor(fetcher: $Fetch) {
|
||||
this.fetcher = fetcher;
|
||||
}
|
||||
|
||||
async confirm(token: string){
|
||||
return await this.fetcher<ConfirmResult>('/auth/confirm', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
token
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async register(email: string, password:string, locale:string){
|
||||
return await this.fetcher<ConfirmResult>('/user/register', {
|
||||
method: 'POST',
|
||||
body:{
|
||||
email, password, locale
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async emailChange(newEmail: string, locale:string){
|
||||
return await this.fetcher<ConfirmResult>('/user/email-update/request', {
|
||||
method: 'POST',
|
||||
body:{
|
||||
newEmail, locale
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async updateDisplayName(newDisplayName: string){
|
||||
return await this.fetcher<ConfirmResult>('/user/update', {
|
||||
method: 'PUT',
|
||||
body:{
|
||||
display_name : newDisplayName
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async deleteRequest(locale:string){
|
||||
return await this.fetcher<ConfirmResult>('/user/delete-request', {
|
||||
method:'DELETE',
|
||||
body:{
|
||||
locale
|
||||
}
|
||||
})
|
||||
}
|
||||
async pwdChallenge(pwd:string){
|
||||
return await this.fetcher<ConfirmResult>('/user/pwdChallenge', {
|
||||
method:'POST',
|
||||
body:{
|
||||
pwd
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user