Skip to content

Commit a83ae62

Browse files
committed
Add model and collection type parameters to generated service methods
1 parent 2f141ff commit a83ae62

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

projects/angular-odata/schematics/apigen/angular/package.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ export class Package {
8282
this.services.push(service);
8383
for (let entitySet of entityContainer.EntitySet ?? []) {
8484
const service = new Service(this, options, entitySet);
85+
const model = this.models.find(m => m.entityType() === service.entityType());
86+
if (model !== undefined) {
87+
service.setModel(model);
88+
}
89+
const collection = this.collections.find(c => c.entityType() === service.entityType());
90+
if (collection !== undefined) {
91+
service.setCollection(collection);
92+
}
8593
this.module.addService(service);
8694
this.index.addDependency(service);
8795
this.services.push(service);

projects/angular-odata/schematics/apigen/angular/service.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import { url, Source } from '@angular-devkit/schematics';
77
import { Schema as ApiGenSchema } from '../schema';
88
import { Package } from './package';
99
import { Import } from './import';
10+
import { Collection } from './collection';
11+
import { Model } from './model';
1012

1113
export class Service extends Base {
14+
model?: Model;
15+
collection?: Collection;
1216
constructor(
1317
pkg: Package,
1418
options: ApiGenSchema,
@@ -32,6 +36,8 @@ export class Service extends Base {
3236
: this.edmElement instanceof CsdlSingleton
3337
? this.edmElement.Type
3438
: this.options.name,
39+
model: this.model,
40+
collection: this.collection,
3541
callables: this.callables ?? [],
3642
};
3743
}
@@ -43,6 +49,14 @@ export class Service extends Base {
4349
: '';
4450
}
4551

52+
setModel(model: Model) {
53+
this.model = model;
54+
this.addDependency(model);
55+
}
56+
setCollection(collection: Collection) {
57+
this.collection = collection;
58+
this.addDependency(collection);
59+
}
4660
public override name() {
4761
return strings.classify(this.edmElement.name()) + 'Service';
4862
}

projects/angular-odata/schematics/apigen/files/entityset-service/__fileName__.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export class <%= classify(name) %> extends ODataEntitySetService<<%= toTypescrip
1717
super(client, '<%= path %>', '<%= type %>');
1818
}
1919
<%= camelize(toTypescriptType(type)) %>Model(entity?: Partial<<%= toTypescriptType(type) %>>) {
20-
return this.model(entity);
20+
return this.model<<%= model.importedName(imports) %><<%= toTypescriptType(type) %>>>(entity);
2121
}
2222
<%= camelize(toTypescriptType(type)) %>Collection(entities?: Partial<<%= toTypescriptType(type) %>>[]) {
23-
return this.collection(entities);
23+
return this.collection<<%= model.importedName(imports) %><<%= toTypescriptType(type) %>>, <%= collection.importedName(imports) %><<%= toTypescriptType(type) %>, <%= model.importedName(imports) %><<%= toTypescriptType(type) %>>>>(entities);
2424
}<% for (let cal of callables) { %>
2525
// <%= cal.name() %>
2626
<%= cal.resourceFunction() %>

0 commit comments

Comments
 (0)