@loomcore/api 0.0.28 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,9 @@ export async function initSystemUserContext(db) {
29
29
  const { OrganizationService } = await import('../services/organization.service.js');
30
30
  const organizationService = new OrganizationService(db);
31
31
  const metaOrg = await organizationService.getMetaOrg(EmptyUserContext);
32
+ if (!metaOrg) {
33
+ throw new Error('Meta organization not found. Please create an organization with isMetaOrg=true before starting the API.');
34
+ }
32
35
  metaOrgId = metaOrg._id;
33
36
  }
34
37
  initializeSystemUserContext(systemEmail, metaOrgId);
@@ -1,6 +1,10 @@
1
1
  import { IAddress } from '@loomcore/common/models';
2
- declare function getSingleLineAddress(address: IAddress): string;
2
+ declare function standardizeField(field: string | undefined | null): string | null;
3
+ declare function getSingleLineAddress(address: IAddress): string | null;
4
+ declare function addFormattedAddress(address: IAddress): IAddress;
3
5
  export declare const addressUtils: {
4
6
  getSingleLineAddress: typeof getSingleLineAddress;
7
+ standardizeField: typeof standardizeField;
8
+ addFormattedAddress: typeof addFormattedAddress;
5
9
  };
6
10
  export {};
@@ -1,15 +1,61 @@
1
+ function isEmptyValue(value) {
2
+ let result = false;
3
+ if (value === null || value === undefined) {
4
+ result = true;
5
+ }
6
+ else if (typeof value === 'string' && value.trim() === '') {
7
+ result = true;
8
+ }
9
+ return result;
10
+ }
11
+ function standardizeField(field) {
12
+ let result = null;
13
+ if (!isEmptyValue(field)) {
14
+ const standardized = field.trim().toUpperCase();
15
+ if (standardized.length > 0) {
16
+ result = standardized;
17
+ }
18
+ }
19
+ return result;
20
+ }
1
21
  function getSingleLineAddress(address) {
2
- const street = address.address1;
3
- let singleLineAddress = `${street}`;
4
- if (address.address2) {
5
- singleLineAddress += ` ${address.address2}`;
22
+ let result = null;
23
+ if (address) {
24
+ const street = standardizeField(address.address1);
25
+ const address2 = standardizeField(address.address2);
26
+ const address3 = standardizeField(address.address3);
27
+ const city = standardizeField(address.city);
28
+ const state = standardizeField(address.state);
29
+ const postalCode = standardizeField(address.postalCode);
30
+ if (street && city && postalCode) {
31
+ let parts = [street];
32
+ if (address2) {
33
+ parts.push(address2);
34
+ }
35
+ if (address3) {
36
+ parts.push(address3);
37
+ }
38
+ parts.push(city);
39
+ let statePostalPart = state;
40
+ statePostalPart += ' ' + postalCode;
41
+ parts.push(statePostalPart);
42
+ result = parts.join(', ');
43
+ }
6
44
  }
7
- if (address.address3) {
8
- singleLineAddress += ` ${address.address3}`;
45
+ return result;
46
+ }
47
+ function addFormattedAddress(address) {
48
+ const formattedAddress = getSingleLineAddress(address);
49
+ if (formattedAddress) {
50
+ return {
51
+ ...address,
52
+ formattedAddress
53
+ };
9
54
  }
10
- singleLineAddress += `, ${address.city}, ${address.state} ${address.postalCode}`;
11
- return singleLineAddress;
55
+ return address;
12
56
  }
13
57
  export const addressUtils = {
14
- getSingleLineAddress
58
+ getSingleLineAddress,
59
+ standardizeField,
60
+ addFormattedAddress
15
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb",
6
6
  "scripts": {