Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomvh committed Jul 4, 2024
1 parent ed232aa commit 328a6cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
14 changes: 7 additions & 7 deletions projects/angular-odata/src/lib/schema/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ODataSchemaElement extends ODataAnnotatable {
* @returns The titleized string.
*/
titleize(term?: string | RegExp): string {
return (term && this.annotatedValue(term)) || Strings.titleCase(this.name);
return (term && this.annotatedValue(term)) ?? Strings.titleCase(this.name);
}

/**
Expand All @@ -44,19 +44,19 @@ export class ODataSchemaElement extends ODataAnnotatable {
* @param type String representation of the type
* @returns True if the callable is type of the given type
*/
isTypeOf(schema: ODataSchemaElement): boolean {
isTypeOf(element: ODataSchemaElement): boolean {
const names = [`${this.schema.namespace}.${this.name}`];
if (this.schema.alias) names.push(`${this.schema.alias}.${this.name}`);
return names.includes(schema.type());
return names.includes(element.type());
}

/**
* Returns a boolean indicating if the structured type is a subtype of the given type.
* @param type String representation of the type
* @returns True if the callable is type of the given type
*/
isSubtypeOf(schema: ODataSchemaElement): boolean {
if (this.isTypeOf(schema)) return true;
isSubtypeOf(element: ODataSchemaElement): boolean {
if (this.isTypeOf(element)) return true;
return false;
}

Expand All @@ -65,8 +65,8 @@ export class ODataSchemaElement extends ODataAnnotatable {
* @param type String representation of the type
* @returns True if the callable is type of the given type
*/
isSupertypeOf(schema: ODataSchemaElement): boolean {
if (this.isTypeOf(schema)) return true;
isSupertypeOf(element: ODataSchemaElement): boolean {
if (this.isTypeOf(element)) return true;
return false;
}
}
Expand Down
21 changes: 5 additions & 16 deletions projects/angular-odata/src/lib/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,14 @@ export class ODataSchema extends ODataAnnotatable {
this.api = api;
this.namespace = config.namespace;
this.alias = config.alias;
this.enums = (config.enums || []).map(
(config) => new ODataEnumType(config, this),
);
this.entities = (config.entities || []).map(
(config) => new ODataStructuredType(config, this),
);
this.callables = OData.mergeCallableParameters(config.callables || []).map(
(config) => new ODataCallable(config, this),
);
this.containers = (config.containers || []).map(
(config) => new ODataEntityContainer(config, this),
);
this.enums = (config.enums ?? []).map((config) => new ODataEnumType(config, this));
this.entities = (config.entities ?? []).map((config) => new ODataStructuredType(config, this));
this.callables = OData.mergeCallableParameters(config.callables ?? []).map((config) => new ODataCallable(config, this));
this.containers = (config.containers ?? []).map((config) => new ODataEntityContainer(config, this));
}

isNamespaceOf(type: string) {
return (
type.startsWith(this.namespace) ||
(this.alias && type.startsWith(this.alias))
);
return (type.startsWith(this.namespace) ?? (this.alias && type.startsWith(this.alias)));
}

get entitySets() {
Expand Down

0 comments on commit 328a6cf

Please sign in to comment.