Skip to content

Commit

Permalink
refactor services
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-sa committed Aug 24, 2024
1 parent 8539d7f commit eed3e35
Show file tree
Hide file tree
Showing 74 changed files with 360 additions and 367 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
"rules": {
"@typescript-eslint/no-empty-interface": ["warn"],
"@typescript-eslint/no-empty-function": ["warn"]
}
},
{
"files": ["*.js", "*.jsx"],
Expand Down
11 changes: 0 additions & 11 deletions accounting-service-api/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions accounting-service-api/src/lib/entities.ts

This file was deleted.

26 changes: 0 additions & 26 deletions accounting-service-api/src/lib/replies.ts

This file was deleted.

29 changes: 0 additions & 29 deletions accounting-service-api/src/lib/services.ts

This file was deleted.

6 changes: 0 additions & 6 deletions accounting-service/.env

This file was deleted.

3 changes: 0 additions & 3 deletions accounting-service/.env.prod

This file was deleted.

54 changes: 0 additions & 54 deletions accounting-service/src/accounting.service.ts

This file was deleted.

3 changes: 0 additions & 3 deletions accounting-service/src/config.ts

This file was deleted.

19 changes: 0 additions & 19 deletions accounting-service/src/main.ts

This file was deleted.

4 changes: 2 additions & 2 deletions api-gateway/src/accounting/accounting.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createModule } from '@deepkit/app';
import { provideRestateServiceProxy } from 'deepkit-restate';

import { AccountingServiceApi } from '@ftgo/accounting-service-api';
import { PaymentServiceApi } from '@ftgo/payment-service-api';

import { AccountingController } from './accounting.controller';

export class AccountingModule extends createModule({
controllers: [AccountingController],
providers: [provideRestateServiceProxy<AccountingServiceApi>()],
providers: [provideRestateServiceProxy<PaymentServiceApi>()],
}) {}
4 changes: 2 additions & 2 deletions api-gateway/src/consumer/consumer.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createModule } from '@deepkit/app';
import { provideRestateServiceProxy } from 'deepkit-restate';

import { ConsumerServiceApi } from '@ftgo/consumer-service-api';
import { CustomerServiceApi } from '@ftgo/customer-service-api';

import { ConsumerController } from './consumer.controller';

export class ConsumerModule extends createModule({
controllers: [ConsumerController],
providers: [provideRestateServiceProxy<ConsumerServiceApi>()],
providers: [provideRestateServiceProxy<CustomerServiceApi>()],
}) {}
30 changes: 11 additions & 19 deletions common/src/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ import {
TypeClass,
} from '@deepkit/type';
import { RestateContextStorage, RestateCustomContext } from 'deepkit-restate';
import {
DatabaseQueryModel,
DeleteResult,
OrmEntity,
PatchResult,
} from '@deepkit/orm';
import { DatabaseQueryModel, OrmEntity } from '@deepkit/orm';

import { Database } from '@ftgo/common';
import { Database } from './database';

export class RestateRepository<E extends OrmEntity> {
readonly #type: TypeClass;
Expand All @@ -30,11 +25,8 @@ export class RestateRepository<E extends OrmEntity> {
return this.contextStorage.getStore()!;
}

async delete(
filter: DatabaseQueryModel<E>['filter'],
): Promise<DeleteResult<E>> {
// TODO: serde
return await this.#ctx.run<DeleteResult<E>>(() =>
async delete(filter: DatabaseQueryModel<E>['filter']): Promise<void> {
await this.#ctx.run(() =>
this.database.query(this.#type.classType).filter(filter).deleteOne(),
);
}
Expand All @@ -53,18 +45,18 @@ export class RestateRepository<E extends OrmEntity> {
async patch(
filter: DatabaseQueryModel<E>['filter'],
changes: ChangesInterface<E> | DeepPartial<E>,
): Promise<PatchResult<E>> {
// TODO: serde
return await this.#ctx.run<PatchResult<E>>(() =>
this.database
): Promise<E> {
return await this.#ctx.run<E>(async () => {
const { returning } = await this.database
.query(this.#type.classType)
.filter(filter)
.patchOne(changes),
);
.patchOne(changes);
return returning as E;
}, this.#type);
}

async create(...args: ConstructorParameters<ClassType<E>>): Promise<E> {
return await this.#ctx.run(async () => {
return await this.#ctx.run<E>(async () => {
const et = new this.#type.classType(...args);
await this.database.persist(et);
return et;
Expand Down
11 changes: 0 additions & 11 deletions consumer-service-api/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions consumer-service-api/src/lib/entities.ts

This file was deleted.

5 changes: 0 additions & 5 deletions consumer-service-api/src/lib/events.ts

This file was deleted.

5 changes: 0 additions & 5 deletions consumer-service/.env

This file was deleted.

3 changes: 0 additions & 3 deletions consumer-service/src/config.ts

This file was deleted.

4 changes: 0 additions & 4 deletions consumer-service/src/consumer.repository.ts

This file was deleted.

File renamed without changes.
11 changes: 11 additions & 0 deletions customer-service-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# customer-service-api

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build customer-service-api` to build the library.

## Running unit tests

Run `nx test customer-service-api` to execute the unit tests via [Vitest](https://vitest.dev/).
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@ftgo/consumer-service-api",
"name": "@ftgo/customer-service-api",
"version": "0.0.1",
"type": "module",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "consumer-service-api",
"name": "customer-service-api",
"$schema": "../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "consumer-service-api/src",
"sourceRoot": "customer-service-api/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/consumer-service-api",
"main": "consumer-service-api/src/index.ts",
"tsConfig": "consumer-service-api/tsconfig.lib.json",
"assets": ["consumer-service-api/*.md"]
"outputPath": "dist/customer-service-api",
"main": "customer-service-api/src/index.ts",
"tsConfig": "customer-service-api/tsconfig.lib.json",
"assets": ["customer-service-api/*.md"]
}
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["{options.reportsDirectory}"],
"options": {
"reportsDirectory": "../coverage/consumer-service-api"
"reportsDirectory": "../coverage/customer-service-api"
}
}
}
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit eed3e35

Please sign in to comment.