-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
1 parent
9c80ce0
commit 76cdcb2
Showing
12 changed files
with
395 additions
and
295 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,110 @@ | ||
import { DataResolver } from './types/DataResolver'; | ||
import { UserProfile } from '@vue-storefront/core/modules/user/types/UserProfile' | ||
import { TaskQueue } from '@vue-storefront/core/lib/sync' | ||
import Task from '@vue-storefront/core/lib/sync/types/Task' | ||
import { adjustMultistoreApiUrl } from '@vue-storefront/core/lib/multistore' | ||
import { processURLAddress } from '@vue-storefront/core/helpers' | ||
import config from 'config' | ||
|
||
const getUrl = (defaultEndpoint) => processURLAddress(config.storeViews.multistore ? adjustMultistoreApiUrl(defaultEndpoint) : defaultEndpoint) | ||
|
||
const headers = { | ||
'Accept': 'application/json, text/plain, */*', | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
const resetPassword = async (email: string): Promise<Task> => | ||
TaskQueue.execute({ | ||
url: config.users.resetPassword_endpoint, | ||
payload: { | ||
method: 'POST', | ||
mode: 'cors', | ||
headers, | ||
body: JSON.stringify({ email }) | ||
} | ||
}) | ||
|
||
const login = async (username: string, password: string): Promise<Task> => | ||
TaskQueue.execute({ | ||
url: getUrl(config.users.login_endpoint), | ||
payload: { | ||
method: 'POST', | ||
mode: 'cors', | ||
headers, | ||
body: JSON.stringify({ username, password }) | ||
} | ||
}) | ||
|
||
const register = async (customer: DataResolver.Customer, password: string): Promise<Task> => | ||
TaskQueue.execute({ | ||
url: getUrl(config.users.create_endpoint), | ||
payload: { | ||
method: 'POST', | ||
headers, | ||
body: JSON.stringify({ customer, password }) | ||
} | ||
}) | ||
|
||
const updateProfile = async (userProfile: UserProfile): Promise<Task> => | ||
TaskQueue.execute({ | ||
url: config.users.me_endpoint, | ||
payload: { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
mode: 'cors', | ||
body: JSON.stringify(userProfile) | ||
} | ||
}) | ||
|
||
const getProfile = async () => | ||
TaskQueue.execute({ | ||
url: config.users.me_endpoint, | ||
payload: { | ||
method: 'GET', | ||
mode: 'cors', | ||
headers | ||
} | ||
}) | ||
|
||
const getOrdersHistory = async (): Promise<Task> => | ||
TaskQueue.execute({ | ||
url: config.users.history_endpoint, | ||
payload: { | ||
method: 'GET', | ||
mode: 'cors', | ||
headers | ||
} | ||
}) | ||
|
||
const changePassword = async (passwordData: DataResolver.PasswordData): Promise<Task> => | ||
TaskQueue.execute({ | ||
url: config.users.changePassword_endpoint, | ||
payload: { | ||
method: 'POST', | ||
mode: 'cors', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(passwordData) | ||
} | ||
}) | ||
|
||
const invalidateToken = async (refreshToken: string): Promise<Task> => | ||
TaskQueue.execute({ | ||
url: getUrl(config.users.refresh_endpoint), | ||
payload: { | ||
method: 'POST', | ||
mode: 'cors', | ||
headers, | ||
body: JSON.stringify({ refreshToken }) | ||
} | ||
}) | ||
|
||
export const UserService: DataResolver.UserService = { | ||
resetPassword, | ||
login, | ||
register, | ||
updateProfile, | ||
getProfile, | ||
getOrdersHistory, | ||
changePassword, | ||
invalidateToken | ||
} |
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,5 +1,7 @@ | ||
import { CategoryService } from './CategoryService'; | ||
import { UserService } from './UserService'; | ||
|
||
export { | ||
CategoryService | ||
CategoryService, | ||
UserService | ||
} |
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
Oops, something went wrong.