#Microservice or not in this use case

25 messages · Page 1 of 1 (latest)

fickle cypress
#

Microservice or not in this use case

echo flax
#

"micro-service" designates standalone code that lives outside of your app

#

Here if the question is "should I merge user and alarm services" the answer is "most likely absolutely not"

#

just have an agnostic alarm service that take users (or a subset of it, or something that looks like it) as an arg of needed methods

#

coupling both you will most likely regret it hard later

fickle cypress
echo flax
#

Note that it's ok to call say the UserModel (or UserService) from the AlarmService

fickle cypress
#

Alert.entity is:

import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  UpdateDateColumn
} from 'typeorm'
import { Customer } from '@rest-api/customers/entities/customer.entity'
import { AbstractEntity } from '@app/common';

@Entity()
export class Alert extends AbstractEntity<Alert>{
  @ApiProperty()
  @Column({ default: 0, type: 'integer' })
  severity: number

  @Column({ length: 100 })
  description: string

  @CreateDateColumn()
  createdAt: number

  @UpdateDateColumn()
  updatedAt: number

  @Column()
  customerId: string

  @ManyToOne(() => Customer, (customer) => customer.alerts)
  customer: Customer
}

Customer is related with another entity in other sub-app. My solution has been remove alarm sub-app, thinking maybe is a little overengineering for this use case

echo flax
#

what does "sub-app" mean ?

fickle cypress
#

sub-app is terminology of nest workspaces https://docs.nestjs.com/cli/monorepo

echo flax
#

does it refer to the same data in the same db ?

fickle cypress
#

in one app I have customers and in other app alerts for those customers

echo flax
#

yes but do these apps share the same db ?

fickle cypress
#

yes

echo flax
#

and the problem is the entity relationship cannot be made for some reason ?

fickle cypress
#

it was a problem typeorm was not finding the relationship

echo flax
#

was or is ?

fickle cypress
#

now is working because it is not a "microservice", at the beginning of the day was a "microservice"

echo flax
#

probably the Customer model wasn't loaded in your alert typeorm instance

#

did you get an error message ?

fickle cypress
#

I will try to return to my init idea... but I think is not necessary...

fickle cypress
echo flax
fickle cypress
#

thank u @echo flax