Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // FOR_OF =========================
- async function modifyResourceFromDatabase(
- resource: IWithId,
- resourceMeta: ResourceMeta,
- userId: string,
- resourceFromDb: IWithId | null = null,
- isCalledFromOutside: boolean = false
- ) {
- const clrType = resourceTypeProvider.getResourceTypeByName(resourceMeta.resourceName);
- if (!resourceFromDb) {
- resourceFromDb = await typeRepository.getOneById(clrType, resource.id);
- }
- for (const propertyMeta of Object.values(resourceMeta.properties)) {
- if (((propertyMeta.isOutsideEditable && isCalledFromOutside) || !isCalledFromOutside)
- && propertyMeta.type !== PropertyType.Object
- && propertyMeta.type !== PropertyType.Array) {
- const newPropertyValue = propertyMetaReflectionService.getPropertyValue(resource, propertyMeta);
- const existingPropertyValue = propertyMetaReflectionService.getPropertyValue(resourceFromDb, propertyMeta);
- if ((newPropertyValue !== null && !isEqual(newPropertyValue, existingPropertyValue)) ||
- (existingPropertyValue !== null && !isEqual(existingPropertyValue, newPropertyValue))) {
- await permissionChecker.checkPropertyPermission(resourceMeta, CrudAction.Update, userId,
- resource, propertyMeta.id);
- }
- propertyMetaReflectionService.setPropertyValueFromAnotherResource(resourceFromDb, resource, propertyMeta);
- }
- }
- if (editBaseResourceService.isBaseResource(clrType)) {
- await editBaseResourceService.setModifiedProperties(resourceFromDb as IBaseResource, userId);
- }
- return resourceFromDb;
- }
- //forEach ===============================
- async function modifyResourceFromDatabase(
- resource: IWithId,
- resourceMeta: ResourceMeta,
- userId: string,
- resourceFromDb: IWithId | null = null,
- isCalledFromOutside: boolean = false
- ) {
- const clrType = resourceTypeProvider.getResourceTypeByName(resourceMeta.resourceName);
- if (!resourceFromDb) {
- resourceFromDb = await typeRepository.getOneById(clrType, resource.id);
- }
- Object.values(resourceMeta.properties).forEach(async (propertyMeta) => {
- if (((propertyMeta.isOutsideEditable && isCalledFromOutside) || !isCalledFromOutside)
- && propertyMeta.type !== PropertyType.Object
- && propertyMeta.type !== PropertyType.Array) {
- const newPropertyValue = propertyMetaReflectionService.getPropertyValue(resource, propertyMeta);
- const existingPropertyValue = propertyMetaReflectionService.getPropertyValue(resourceFromDb, propertyMeta);
- if ((newPropertyValue !== null && !isEqual(newPropertyValue, existingPropertyValue)) ||
- (existingPropertyValue !== null && !isEqual(existingPropertyValue, newPropertyValue))) {
- await permissionChecker.checkPropertyPermission(resourceMeta, CrudAction.Update, userId,
- resource, propertyMeta.id);
- }
- propertyMetaReflectionService.setPropertyValueFromAnotherResource(resourceFromDb, resource, propertyMeta);
- }
- });
- if (editBaseResourceService.isBaseResource(clrType)) {
- await editBaseResourceService.setModifiedProperties(resourceFromDb as IBaseResource, userId);
- }
- return resourceFromDb;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement