Skip to content

Commit

Permalink
feat(create): add organization and user to owner entity
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Feb 3, 2025
1 parent 8e92912 commit 6728123
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as accountSelectors from './account.selectors';
export class AccountFacade {
// Selectors
user$ = this.store.select(accountSelectors.selectUser);
userId$ = this.store.select(accountSelectors.selectUserId);
actionStatus$ = this.store.select(accountSelectors.selectActionStatus);
error$ = this.store.select(accountSelectors.selectError);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const selectUser = createSelector(
(state: IAccountState) => state.user
);

export const selectUserId = createSelector(selectUser, (user) => user?.id);

export const selectActionStatus = createSelector(
selectAccount,
(state: IAccountState) => state.actionStatus
Expand Down
37 changes: 2 additions & 35 deletions packages/core/state/src/lib/+state/product/product.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,6 @@ import {
import * as productActions from './product.actions';
import * as productSelectors from './product.selectors';

const addTemporaryMetaForCatalogSrv = (
// Hack for catalog srv. Can't wait for it to be fixed!
payload: IIoRestorecommerceProductProductList
) => {
const item = (payload.items ?? [])[0];

//TODO Change this ASAP. Hack to this bloody catalog-srv.
if (item) {
item.meta = {
owners: [
{
id: 'urn:restorecommerce:acs:names:ownerIndicatoryEntity',
value: 'urn:restorecommerce:acs:model:organization.Organization',
attributes: [
{
id: 'urn:restorecommerce:acs:names:ownerInstance',
value: 'nfuse-shop-000-organization',
},
],
},
],
};
}

return payload;
};

@Injectable()
export class ProductFacade {
// Selectors
Expand Down Expand Up @@ -65,17 +38,11 @@ export class ProductFacade {
this.store.dispatch(productActions.setSelectedId({ payload }));

create = (payload: IIoRestorecommerceProductProductList) => {
const tempPayload = addTemporaryMetaForCatalogSrv(payload);
this.store.dispatch(
productActions.productCreateRequest({ payload: tempPayload })
);
this.store.dispatch(productActions.productCreateRequest({ payload }));
};

update = (payload: IIoRestorecommerceProductProductList) => {
const tempPayload = addTemporaryMetaForCatalogSrv(payload);
this.store.dispatch(
productActions.productUpdateRequest({ payload: tempPayload })
);
this.store.dispatch(productActions.productUpdateRequest({ payload }));
};

remove = (payload: { id: string }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface ISchemaOptions {
export const buildProductSchema = (
options: ISchemaOptions
): VCLFormFieldSchemaRoot => {

return {
type: 'form',
fields: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import {
Component,
EventEmitter,
Input,
OnInit,
Output,
ViewChild,
} from '@angular/core';
import { combineLatest } from 'rxjs';

import { JssFormComponent, VCLFormFieldSchemaRoot } from '@vcl/ng-vcl';

import { ModeType } from '@console-core/graphql';
import { AccountFacade, OrganizationFacade } from '@console-core/state';

@Component({
selector: 'rc-crud-create',
Expand All @@ -30,10 +33,13 @@ import { ModeType } from '@console-core/graphql';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class RcCrudCreateComponent {
export class RcCrudCreateComponent implements OnInit {
@Input({ required: true })
schema!: VCLFormFieldSchemaRoot;

currentOrganizationId!: string;
userId!: string;

@Input({ required: true })
// eslint-disable-next-line @typescript-eslint/no-explicit-any
create!: (data: any) => void;
Expand All @@ -43,6 +49,28 @@ export class RcCrudCreateComponent {

@Output() actionEvent = new EventEmitter<string>();

constructor(
private accountFacade: AccountFacade,
private organizationFacade: OrganizationFacade
) {}

ngOnInit(): void {
combineLatest([
this.organizationFacade.globalOrganizationLeafId$,
this.organizationFacade.globalOrganizationId$,
]).subscribe(([leafOrganizationId, organizationId]) => {
this.currentOrganizationId = leafOrganizationId
? leafOrganizationId
: organizationId;
});

this.accountFacade.userId$.subscribe((userId) => {
if (userId) {
this.userId = userId;
}
});
}

onAction(action: string): void {
this.actionEvent.emit(action);
this.createForm.form.resetForm(this.createForm.defaultValue);
Expand All @@ -54,7 +82,36 @@ export class RcCrudCreateComponent {
}

this.create({
items: [this.createForm.form.value],
items: [
{
...this.createForm.form.value,
meta: {
owners: [
{
id: 'urn:restorecommerce:acs:names:ownerIndicatoryEntity',
value:
'urn:restorecommerce:acs:model:organization.Organization',
attributes: [
{
id: 'urn:restorecommerce:acs:names:ownerInstance',
value: this.currentOrganizationId,
},
],
},
{
id: 'urn:restorecommerce:acs:names:ownerIndicatoryEntity',
value: 'urn:restorecommerce:acs:model:user.User',
attributes: [
{
id: 'urn:restorecommerce:acs:names:ownerInstance',
value: this.userId,
},
],
},
],
},
},
],
mode: ModeType.Create,
});
}
Expand Down

0 comments on commit 6728123

Please sign in to comment.