Skip to content

Repositories

  • Preferred location (for context): src/app/contexts/{ContextName}/infrastructure/http/repositories

From an implementation perspective, repositories have no restrictions. Below is an example of integration as the package suggests for repository implementation and data source integration. Examples of data source and response for data source are in the previous sections.

typescript
// This example uses the data source from the example in the previous section
// Imported from /core folder, which you can read about in the architecture section
// This alias and the source itself can be generated using @azure-net/cli (read about it in the CLI section)
import { MyCustomDatasource } from '$core';

export class MyRepository {
  constructor(private datasource: MyCustomDatasource) {}

  async collection(query?: MyQueryType) {
    return this.datasource.createRequest<IUser[]>(({ http, query }) => http.get(`/users${query.build(query)}`))
        // In then, we get an instance of our response created in the previous sections
        .then((res) => res.paginate().get());
  }

  async create(data: MyCreateRequest) {
    return this.datasource.createRequest<IUser>(({ http }) => http.post('/users', { json: data }));
  }
}