Effect CommunityEC
Effect Community2y ago
24 replies
ryan

Adding Server-Generated Timestamps to Bet Schema

I'm creating a basic schema, for a "bet". I want to "add fields" to the bet when its "created".

For example:
class Bet extends S.TaggedClass<Bet>()(
  'Bet',
  S.Struct({
    id: S.UUID,
    name: S.String,
    odds: S.Number,
    stake: S.Number,
    status: S.Union(
      S.Literal('OPEN'),
      S.Literal('CLOSED'),
      S.Literal('PENDING'),
      S.Literal('WON'),
      S.Literal('LOST')
    ),
    createdAt: S.DateFromNumber,
    updatedAt: S.DateFromNumber,
  })
)


I want to create the createdAt and updatedAt and probably the uuid fields on the server. So the client wouldn't submit those, but the server could respond to the client with those fields.

Is this something I would handle in a schema? It feels like its possible, i just haven't figured out exactly where/how it would be done. Would this be considered a transformation? Or is this two different schemas I should make?

basically i want effect-http to make a client that doesn't need these fields, and then the server side I can add them. not sure if this is possible?
Was this page helpful?