Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99fb885ba4 |
@@ -2,5 +2,6 @@ export const UMB_CURRENT_USER_STORE_ALIAS = 'Umb.Store.CurrentUser';
|
||||
export const UMB_CURRENT_USER_REPOSITORY_ALIAS = 'Umb.Repository.CurrentUser';
|
||||
export const UMB_CURRENT_USER_CONFIG_REPOSITORY_ALIAS = 'Umb.Repository.CurrentUser.Config';
|
||||
export const UMB_CURRENT_USER_CONFIG_STORE_ALIAS = 'Umb.Store.CurrentUser.Config';
|
||||
export const UMB_CURRENT_USER_DATA_REPOSITORY_ALIAS = 'Umb.Repository.CurrentUser.Data';
|
||||
export { UMB_CURRENT_USER_STORE_CONTEXT } from './current-user.store.token.js';
|
||||
export { UMB_CURRENT_USER_CONFIG_STORE_CONTEXT } from './current-user-config.store.token.js';
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
import { UmbCurrentUserDataServerDataSource } from './current-user-data.server.data-source.js';
|
||||
import type {
|
||||
CreateUserDataRequestModel,
|
||||
UpdateUserDataRequestModel,
|
||||
} from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
/**
|
||||
* A repository for the current user data
|
||||
* @class UmbCurrentUserDataRepository
|
||||
* @augments {UmbRepositoryBase}
|
||||
*/
|
||||
export class UmbCurrentUserDataRepository extends UmbRepositoryBase {
|
||||
#dataSource = new UmbCurrentUserDataServerDataSource(this._host);
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all user data for the current user
|
||||
* @param {{ groups?: Array<string>; identifiers?: Array<string>; skip?: number; take?: number }} [args]
|
||||
* @memberof UmbCurrentUserDataRepository
|
||||
*/
|
||||
async getUserData(args?: { groups?: Array<string>; identifiers?: Array<string>; skip?: number; take?: number }) {
|
||||
return this.#dataSource.getUserData(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user data by id
|
||||
* @param {string} id
|
||||
* @memberof UmbCurrentUserDataRepository
|
||||
*/
|
||||
async getUserDataById(id: string) {
|
||||
return this.#dataSource.getUserDataById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user data
|
||||
* @param {CreateUserDataRequestModel} body
|
||||
* @memberof UmbCurrentUserDataRepository
|
||||
*/
|
||||
async createUserData(body: CreateUserDataRequestModel) {
|
||||
return this.#dataSource.createUserData(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user data
|
||||
* @param {UpdateUserDataRequestModel} body
|
||||
* @memberof UmbCurrentUserDataRepository
|
||||
*/
|
||||
async updateUserData(body: UpdateUserDataRequestModel) {
|
||||
return this.#dataSource.updateUserData(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user data by id
|
||||
* @param {string} id
|
||||
* @memberof UmbCurrentUserDataRepository
|
||||
*/
|
||||
async deleteUserData(id: string) {
|
||||
return this.#dataSource.deleteUserData(id);
|
||||
}
|
||||
}
|
||||
|
||||
export default UmbCurrentUserDataRepository;
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import type {
|
||||
CreateUserDataRequestModel,
|
||||
UpdateUserDataRequestModel,
|
||||
} from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import { UserDataService } from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import { tryExecute } from '@umbraco-cms/backoffice/resources';
|
||||
|
||||
/**
|
||||
* A data source for the current user data that fetches data from the server
|
||||
* @class UmbCurrentUserDataServerDataSource
|
||||
*/
|
||||
export class UmbCurrentUserDataServerDataSource {
|
||||
#host;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all user data for the current user
|
||||
* @param {{ groups?: Array<string>; identifiers?: Array<string>; skip?: number; take?: number }} [args]
|
||||
* @memberof UmbCurrentUserDataServerDataSource
|
||||
*/
|
||||
getUserData(args?: { groups?: Array<string>; identifiers?: Array<string>; skip?: number; take?: number }) {
|
||||
return tryExecute(this.#host, UserDataService.getUserData({ query: args }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user data by id
|
||||
* @param {string} id
|
||||
* @memberof UmbCurrentUserDataServerDataSource
|
||||
*/
|
||||
getUserDataById(id: string) {
|
||||
return tryExecute(this.#host, UserDataService.getUserDataById({ path: { id } }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user data
|
||||
* @param {CreateUserDataRequestModel} body
|
||||
* @memberof UmbCurrentUserDataServerDataSource
|
||||
*/
|
||||
createUserData(body: CreateUserDataRequestModel) {
|
||||
return tryExecute(this.#host, UserDataService.postUserData({ body }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user data
|
||||
* @param {UpdateUserDataRequestModel} body
|
||||
* @memberof UmbCurrentUserDataServerDataSource
|
||||
*/
|
||||
updateUserData(body: UpdateUserDataRequestModel) {
|
||||
return tryExecute(this.#host, UserDataService.putUserData({ body }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user data by id
|
||||
* @param {string} id
|
||||
* @memberof UmbCurrentUserDataServerDataSource
|
||||
*/
|
||||
deleteUserData(id: string) {
|
||||
return tryExecute(this.#host, UserDataService.deleteUserDataById({ path: { id } }));
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export { UmbCurrentUserConfigRepository } from './current-user-config.repository.js';
|
||||
export { UmbCurrentUserDataRepository } from './current-user-data.repository.js';
|
||||
export { UmbCurrentUserRepository } from './current-user.repository.js';
|
||||
export { UmbCurrentUserStore } from './current-user.store.js';
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
UMB_CURRENT_USER_REPOSITORY_ALIAS,
|
||||
UMB_CURRENT_USER_CONFIG_REPOSITORY_ALIAS,
|
||||
UMB_CURRENT_USER_CONFIG_STORE_ALIAS,
|
||||
UMB_CURRENT_USER_DATA_REPOSITORY_ALIAS,
|
||||
} from './constants.js';
|
||||
import { UmbCurrentUserStore } from './current-user.store.js';
|
||||
import { UmbCurrentUserConfigStore } from './current-user-config.store.js';
|
||||
@@ -32,4 +33,10 @@ export const manifests: Array<UmbExtensionManifest> = [
|
||||
name: 'Current User Config Repository',
|
||||
api: () => import('./current-user-config.repository.js'),
|
||||
},
|
||||
{
|
||||
type: 'repository',
|
||||
alias: UMB_CURRENT_USER_DATA_REPOSITORY_ALIAS,
|
||||
name: 'Current User Data Repository',
|
||||
api: () => import('./current-user-data.repository.js'),
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user