Reservation time
2 min
Business logic (how to use)
On the App settings form in section `Intranet`, you can set up the number of days for reservation time for a car.

By default reservation time is 2 day (minimum is one day)

Technical implementation
Was created new property intranet with type IntranetParams for object hyperDealerApps
For this time IntranetParams contains only reservationDuration param.
To create all needed changes in the database of all tenants has created this migration:
////////////////////////////////////////////////
// Full code of file with migration (For staging)
////////////////////////////////////////////////
process.env.AWS_ACCESS_KEY_ID = '**************';
process.env.AWS_SECRET_ACCESS_KEY = '******************';
process.env.AWS_REGION = 'eu-west-1';
//--------------------------------------------------------------
// DEFINE RUNTIME VARIABLES
//--------------------------------------------------------------
process.env.FunctionName = 'staging-hyper-dealer-UpdateAppFunction-V3CCW53G2W5C';
process.env.ENV = 'staging';
process.env.APP_EVENTS_SNS_TOPIC =
'arn:aws:sns:eu-west-1:114776656493:staging-custom-data-CustomDataSNSTopic-WNF1Y5DVZW6Y';
process.env.BUILD_VERSION = 'e22dd004.1598465313574';
process.env.CONSOLE_LOG_LEVEL = 'info';
process.env.CORE_GET_TENANT_ARN =
'arn:aws:lambda:eu-west-1:114776656493:function:staging-core-InternalGetTenantFunction-QLILNGBGS0HY';
process.env.CORE_UPDATE_TENANT_ARN =
'arn:aws:lambda:eu-west-1:114776656493:function:staging-core-InternalUpdateTenantFunction-1493YP4MVPYT5';
process.env.DB_PURPOSE = 'WRITE';
process.env.DB_PWD = 'e60Gf6XDeSG6';
process.env.DB_USER = 'custom_data/writer';
process.env.ENABLE_DOMAINS_JOB_QUEUE_URL =
'https://sqs.eu-west-1.amazonaws.com/114776656493/staging-custom-data-EnableDomainsJobQueue-17DMVGG01VK1';
process.env.ES_HOST = 'https://bd6f8faef8014207bdffac03e35cee85.eu-west-1.aws.found.io:9243';
process.env.ES_HTTP_AUTH = 'elastic:n5KOG793jgz27zonU4YASJfa';
process.env.ES_INDEX_ALL_ENTITIES_JOB_QUEUE_URL =
'https://sqs.eu-west-1.amazonaws.com/114776656493/staging-custom-data-EsIndexAllEntitiesJobQueue-I0I3VU3X7EGR';
process.env.ES_REMAP_REFERRING_DEFINITIONS_JOB_QUEUE_URL =
'https://sqs.eu-west-1.amazonaws.com/114776656493/staging-custom-data-EsRemapReferringDefinitionsJobQueue-BC3HRVMKO7GS';
process.env.EXPORT_CMS_EXCEL_JOB_QUEUE_URL =
'https://sqs.eu-west-1.amazonaws.com/114776656493/staging-custom-data-ExportCmsExcelJobQueue-18F4LXTHL8Y0G';
process.env.IMPORT_CMS_EXCEL_JOB_QUEUE_URL =
'https://sqs.eu-west-1.amazonaws.com/114776656493/staging-custom-data-ImportCmsExcelJobQueue-O96PHLU0IIZY';
process.env.IMPORT_CMS_EXCEL_JOB_QUEUE_ARN =
'arn:aws:sqs:eu-west-1:114776656493:staging-custom-data-ImportCmsExcelJobQueue-O96PHLU0IIZY';
process.env.MAIL_SEND_TEMPLATED_EMAIL_LAMBDA_ARN =
'arn:aws:lambda:eu-west-1:114776656493:function:staging-mail-InternalSendTemplatedEmailFunction-A2581GCD4SK7';
process.env.PROCESS_REFERRING_ENTITIES_JOB_QUEUE_URL =
'https://sqs.eu-west-1.amazonaws.com/114776656493/staging-custom-data-ProcessReferringEntitiesJobQueue-1JGNRIVST2V6X';
process.env.RECOMPUTE_DEFINITION_ENTITIES_JOB_QUEUE_URL =
'https://sqs.eu-west-1.amazonaws.com/114776656493/staging-custom-data-RecomputeDefinitionEntitiesJobQueue-1NK2XFLOVYAO4';
process.env.STORAGE_INVOKE_INTERNAL_LAMBDA_ARN =
'arn:aws:lambda:eu-west-1:114776656493:function:staging-storage-service-InvokeInternalHandlerFunct-1LR6CU8AWNQK2';
process.env.STORAGE_UPLOAD_FILE_LAMBDA_ARN =
'arn:aws:lambda:eu-west-1:114776656493:function:staging-storage-service-InternalUploadFileFunction-1KKU0RKECTDYA';
process.env.UPDATE_ALL_DYNAMIC_ENTITY_PERMISSIONS_JOB_QUEUE_URL =
'https://sqs.eu-west-1.amazonaws.com/114776656493/staging-custom-data-UpdateAllDynamicEntityPermissionsJobQueue-APKH2JROGEJ6';
process.env.CMS_INVOKE_INTERNAL_HANDLER_ARN =
'arn:aws:lambda:eu-west-1:114776656493:function:staging-custom-data-InvokeInternalHandlerFunction-13E8Y4AL2SEFA';
process.env.STORAGE_INVOKE_INTERNAL_HANDLER_ARN =
'arn:aws:lambda:eu-west-1:114776656493:function:staging-storage-service-InvokeInternalHandlerFunct-1LR6CU8AWNQK2';
process.env.CONFIGS_INTERNAL_SAVE_CONFIG_LAMBDA_ARN =
'arn:aws:lambda:eu-west-1:114776656493:function:staging-configs-service-InternalSaveConfigFunction-LER2VA7LBPQ3';
process.env.CORE_INTERNAL_GET_TENANT_BY_HOST_ARN =
'arn:aws:lambda:eu-west-1:114776656493:function:staging-core-InternalGetTenantByHostFunction-1P3XHB48VKCZ';
process.env.IREACH_IMPORT_BUCKET_NAME = 'staging-ireach-import';
import { runConfig } from '../src/config';
import { getDb, getEnvDbOptions } from '@hypercharge/lambda-utils/lib/mysqlFactory';
import { getEs, getEnvEsOptions } from '@hypercharge/lambda-utils/lib/search/elasticsearch';
import { updateApp, createApp } from '../../hyper-dealer/src/lib/integration/apps';
import { getApps } from '../../hyper-dealer/src/lib/utils';
import { App } from '../../hyper-dealer/src/types';
import { getDefinition, saveDefinition } from '../../hyper-dealer/src/lib/utils/cms';
import { PropertyTypes } from '../lib/types';
import { INTEGRATION_HYPER_DEALER_INTRANET_ID } from '../../hyper-dealer/src/constants';
import { HYPER_ADMINS_GROUP } from '@hypercharge/lambda-utils/lib/constants';
import { getTenantByHost } from '../../core/src/tenants/lib/lib';
import { getHyperDealerTenants } from '../../hyper-dealer/src/lib/libData';
runConfig.appEventsSnsTopicArn = <string>process.env.APP_EVENTS_SNS_TOPIC;
runConfig.enableDomainsJobQueueUrl = <string>process.env.ENABLE_DOMAINS_JOB_QUEUE_URL;
runConfig.importCmsExcelJobQueueUrl = <string>process.env.IMPORT_CMS_EXCEL_JOB_QUEUE_URL;
runConfig.importCmsExcelJobQueueArn = <string>process.env.IMPORT_CMS_EXCEL_JOB_QUEUE_ARN;
runConfig.exportCmsExcelJobQueueUrl = <string>process.env.EXPORT_CMS_EXCEL_JOB_QUEUE_URL;
runConfig.processReferringEntitiesJobQueueUrl = <string>(
process.env.PROCESS_REFERRING_ENTITIES_JOB_QUEUE_URL
);
runConfig.esRemapReferringDefinitionsJobQueueUrl = <string>(
process.env.ES_REMAP_REFERRING_DEFINITIONS_JOB_QUEUE_URL
);
runConfig.esIndexAllEntitiesJobQueueUrl = <string>process.env.ES_INDEX_ALL_ENTITIES_JOB_QUEUE_URL;
runConfig.recomputedDefinitionEntitiesJobQueueUrl = <string>(
process.env.RECOMPUTE_DEFINITION_ENTITIES_JOB_QUEUE_URL
);
runConfig.updateDynamicEntityPermissionsJobQueueUrl = <string>(
process.env.UPDATE_ALL_DYNAMIC_ENTITY_PERMISSIONS_JOB_QUEUE_URL
);
runConfig.coreGetTenantArn = <string>process.env.CORE_GET_TENANT_ARN;
runConfig.coreUpdateTenantArn = <string>process.env.CORE_UPDATE_TENANT_ARN;
runConfig.storageUploadFileLambdaArn = <string>process.env.STORAGE_UPLOAD_FILE_LAMBDA_ARN;
runConfig.storageInvokeInternalLambdaArn = <string>process.env.STORAGE_INVOKE_INTERNAL_LAMBDA_ARN;
runConfig.mailSendTemplatedEmailLambdaArn = <string>(
process.env.MAIL_SEND_TEMPLATED_EMAIL_LAMBDA_ARN
);
//--------------------------------------------------------------
// MAIN EXECUTION FUNCTION
//--------------------------------------------------------------
const main = async () => {
try {
// ------------------------------------------------
// SCRIPT INITIALIZATION SECTION BEGIN
await getDb().start(getEnvDbOptions(process.env));
await getEs().start(getEnvEsOptions(process.env));
// SCRIPT FINALIZATION SECTION END
// ------------------------------------------------
// ------------------------------------------------
const tenantIds = await getHyperDealerTenants();
for (let tenantId of tenantIds) {
const res = await getDefinition(tenantId, 'hyperDealerApps');
const integrations = res.sections.find(e => e.id === 'integrations');
if (
integrations &&
!integrations.properties.some(e => e.propertyId === INTEGRATION_HYPER_DEALER_INTRANET_ID)
) {
integrations.properties.push({
meta: {},
type: PropertyTypes.json,
labels: { en: 'Intranet' },
propertyId: INTEGRATION_HYPER_DEALER_INTRANET_ID,
readGroups: [HYPER_ADMINS_GROUP],
writeGroups: [HYPER_ADMINS_GROUP],
system: true
});
await saveDefinition(tenantId, res);
console.log(`Updated ${tenantId}`);
} else {
console.log(`Skip ${tenantId}`);
}
const hyperDealerApps = await getApps(tenantId);
hyperDealerApps.forEach(async app => {
console.log(tenantId, app.entityId, app.intranet);
if (!app.intranet) {
app.intranet = { reservationDuration: 2 };
}
await updateApp(tenantId, app.entityId, app);
});
}
// SCRIPT BODY SECTION END
// ------------------------------------------------
} catch (e) {
console.log(JSON.stringify(e, null, 2));
} finally {
// ------------------------------------------------
// SCRIPT FINALIZATION SECTION BEGIN
await getDb().end();
await getEs().end();
// SCRIPT FINALIZATION SECTION END
// ------------------------------------------------
}
};
main();
Additionally was added code for three projcts: