-
Notifications
You must be signed in to change notification settings - Fork 4
(feat): updated contact model with accord PhoneNumber and Email types #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dsromannebeliuk
wants to merge
2
commits into
main
Choose a base branch
from
roman/add-contact-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
concerto version "^3.0.0" | ||
namespace [email protected] | ||
|
||
/* | ||
* Definitions in this file do not enforce character constraints (for example, using | ||
* regular expressions or digits). It is the responsibility of the application to enforce | ||
* theseconstraints. This allows broader compatibility between systems and agreements which | ||
* may have different requirements. | ||
*/ | ||
|
||
/* | ||
* An email address without enclosing angle brackets | ||
* | ||
* Note: There is a restriction in RFC 2821 on the length of an | ||
* address in MAIL and RCPT commands of 254 characters | ||
* https://www.rfc-editor.org/errata_search.php?rfc=3696 | ||
*/ | ||
scalar EmailAddress extends String length=[,254] | ||
|
||
/* | ||
* A representation of telephone numbers to define commonly used structures | ||
*/ | ||
concept PhoneNumber { | ||
/* | ||
* A formatted E.123 national number, potentially including spaces parentheses | ||
* and separators (e.g. '-'). Does not include an International Prefix, extension, | ||
* trunk prefix or alternate endings. | ||
* https://www.itu.int/rec/T-REC-E.123-200102-I/en | ||
*/ | ||
o String number length=[0,32] | ||
|
||
/* | ||
* A standardized E.164 international telephone number without formatting such | ||
* as spaces, parentheses or separators (e.g. '-'). Includes the International Prefix | ||
* and Subscriber Number (National Destination Code and Base Number). Does not | ||
* include an extension, trunk prefix or alternate endings. | ||
* https://www.itu.int/rec/T-REC-E.164-201011-I/en | ||
*/ | ||
o String normalizedNumber length=[,15] optional | ||
|
||
/* | ||
* An E.164 Network Address Extension / Sub-address ("Ext.", Direct Dial In, | ||
* or Direct Inward Dial) number. Does not include a "Ext." characters. | ||
* https://www.itu.int/rec/T-REC-E.164-201011-I/en | ||
*/ | ||
o String extension length=[0,6] optional | ||
|
||
/* | ||
* The International Prefix or Country Code (CC) for the telephone number. Includes | ||
* the leading '+' character or zeros. The International Prefix has 1-3 digits. | ||
* https://www.itu.int/rec/T-REC-E.164-201011-I/en | ||
*/ | ||
o String countryCode length=[0,7] optional | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
namespace [email protected] | ||
import [email protected].{EmailAddress, PhoneNumber} | ||
|
||
enum AccountType_Enum { | ||
o Prospect | ||
|
@@ -165,11 +166,11 @@ concept Contact identified by Id { | |
|
||
@Term("Email") | ||
@Crud("Createable,Readable,Updateable") | ||
o String email optional | ||
o EmailAddress email optional | ||
|
||
@Term("Phone") | ||
@Crud("Createable,Readable,Updateable") | ||
o String phone optional | ||
o PhoneNumber phone optional | ||
|
||
@Term("Opportunity Link") | ||
@Crud("Createable,Readable,Updateable") | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,21 @@ | |
"Id": "1", | ||
"fullName": "Sarah Johnson", | ||
"email": "[email protected]", | ||
"phone": "+1-415-555-0193", | ||
"phone": { | ||
"number":"4155550193", | ||
"countryCode":"1", | ||
"extension":"999" | ||
}, | ||
"currentOpportunity": "1" | ||
}, | ||
{ | ||
"Id": "2", | ||
"fullName": "Michael Chen", | ||
"email": "[email protected]", | ||
"phone": "+1-510-555-0176", | ||
"phone": { | ||
"number":"5105550176", | ||
"countryCode":"1" | ||
}, | ||
"currentOpportunity": "2" | ||
} | ||
] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { IReq, IRes } from '../utils/types'; | |
import { QueryExecutor } from '../utils/queryExecutor'; | ||
import { FileDB } from '../db/fileDB'; | ||
import moment from 'moment'; | ||
import { ConceptDeclaration, ModelManager } from '@accordproject/concerto-core'; | ||
import { ConceptDeclaration, EnumDeclaration, MapDeclaration, ModelManager, ScalarDeclaration } from '@accordproject/concerto-core'; | ||
import path from 'path'; | ||
import { ModelManagerUtil } from '../utils/modelManagerUtil'; | ||
import { ResultRehydrator } from '../utils/resultRehydrator'; | ||
|
@@ -120,8 +120,8 @@ const generateErrorResponse = (message: string, code: string): ErrorResponse => | |
* Concerto model manager setup using CTO file. | ||
* Model manager allowes users to load in CTO files and use Concerto model features directly in code. | ||
*/ | ||
const MODEL_MANAGER: ModelManager = ModelManagerUtil.createModelManagerFromCTO(path.join(__dirname, "../dataModel/model.cto")); | ||
const CONCEPTS: ConceptDeclaration[] = MODEL_MANAGER.getConceptDeclarations(); | ||
const MODEL_MANAGER: ModelManager = ModelManagerUtil.createModelManagerFromCTO(); | ||
const CONCEPTS: ConceptDeclaration[] = MODEL_MANAGER.getModelFile("[email protected]").getConceptDeclarations(); | ||
const READABLE_CONCEPTS: ConceptDeclaration[] = CONCEPTS.filter(isReadableConcept); | ||
|
||
/** | ||
|
@@ -247,11 +247,26 @@ export const getTypeDefinitions = (req: IReq<GetTypeDefinitionsBody>, res: IRes) | |
if (!typeNames) { | ||
return res.status(400).json(generateErrorResponse(ErrorCode.BAD_REQUEST, 'Missing typeNames in request')).send(); | ||
} | ||
MODEL_MANAGER.addCTOModel | ||
|
||
try { | ||
const modelFile = MODEL_MANAGER.getModelFile("[email protected]"); | ||
|
||
return res.json({ | ||
declarations: READABLE_CONCEPTS.map((concept: ConceptDeclaration) => concept.ast) | ||
}) | ||
declarations: [ | ||
...modelFile | ||
.getEnumDeclarations() | ||
.map((decl: EnumDeclaration) => decl.ast), | ||
...modelFile | ||
.getScalarDeclarations() | ||
.map((decl: ScalarDeclaration) => decl.ast), | ||
...modelFile | ||
.getConceptDeclarations() | ||
.map((decl: ConceptDeclaration) => decl.ast), | ||
...modelFile | ||
.getMapDeclarations() | ||
.map((decl: MapDeclaration) => decl.value.ast) | ||
] | ||
}); | ||
} catch (err) { | ||
console.log(`Encountered an error getting type definitions: ${err.message}`); | ||
return res.status(500).json(generateErrorResponse(ErrorCode.INTERNAL_ERROR, err)).send(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,31 @@ import path from "path"; | |
import fs from 'fs'; | ||
|
||
export class ModelManagerUtil { | ||
private static DATA_MODELS_FOLDER: string = '../dataModel/'; | ||
private static DATA_MODLS_FILES: string[] = [ | ||
'[email protected]', | ||
'model.cto', | ||
]; | ||
|
||
/** | ||
* Create a ModelManager instance from a CTO file. | ||
* @param {string} ctoFile - the path to the CTO file. | ||
* @return {ModelManager} a ModelManager instance. | ||
*/ | ||
public static createModelManagerFromCTO(ctoFile: string): ModelManager { | ||
public static createModelManagerFromCTO(): ModelManager { | ||
// Needed as this is a workaround to skip line locations in generated AST | ||
// @ts-ignore | ||
const modelManager: ModelManager = new ModelManager({ strict: true, skipLocationNodes: true }); | ||
modelManager.addCTOModel(fs.readFileSync(path.join(__dirname, "../dataModel/model.cto"),'utf8')); | ||
const modelManager: ModelManager = new ModelManager({ strict: true,skipLocationNodes: true }); | ||
|
||
this.DATA_MODLS_FILES.forEach((fileName: string) => { | ||
dsromannebeliuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
modelManager.addCTOModel( | ||
fs.readFileSync( | ||
path.join(__dirname, `${this.DATA_MODELS_FOLDER}${fileName}`), | ||
'utf8' | ||
) | ||
); | ||
}); | ||
|
||
modelManager.validateModelFiles(); | ||
return modelManager | ||
return modelManager; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.