1.0.24 • Published 2 years ago

@nguyenduclong/mongodbts v1.0.24

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago
import { SchemaTypes } from 'mongoose'
import {
  Field,
  Reposiory,
  repository,
  Entity,
  Timestamp,
  Before,
  After,
} from 'mongodbts'

/** Declare for User schema */
@Entity({ id: true })
class User implements Timestamp {
  @Field(String)
  name: string

  @Field(String)
  username: string

  @Field([{ type: SchemaTypes.ObjectId }])
  posts?: []
}

/** Here is Repository for User model */
@repository(User)
export class UserRepository extends Reposiory<User> {
  @Before('findOne')
  beforeFindOne(ctx: any) {
    // Hook call before findOne
    ctx.meta.beforeIsCall = true
  }

  @After('findOne')
  afterFindOne(ctx: any, result: any) {
    // Hook call after findOne
    // result is return of action findOne or prev afterHook
    // In afterHook, must be return result to next afterHook
    ctx.meta.afterIsCall = true
    return rs
  }

  @Action()
  hello() {
    // Declare action
    return 'Hello'
  }
}

Actions

- create (ctx: ContextCreate\): Promise\<E>

interface ContextCreate<E = any, M = { cascadeContext?: CascadeContext }>
  extends Context<M> {
  // Query for check existed, if set then check entity existed with query before
  // If Exist throw error
  query?: FilterQuery<E>
  data: E
  session?: any
  safe?: boolean
  populates?: (keyof E)[] | Array<PopulateOptions>
}

- createMany (ctx: ContextCreate\): Promise\<E[]>

interface ContextCreateMany<E = any, M = { cascadeContext?: CascadeContext }>
  extends Context<M>,
    ContextOptions<E> {
  // Query for check existed, if set then check entity existed with query before
  // If Exist throw error
  query?: FilterQuery<E>
  data: E[]
  safe?: boolean
  session?: any
  populates?: (keyof E)[] | Array<PopulateOptions>
}
1.0.24

2 years ago

1.0.23

2 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago