1.0.24 • Published 3 years ago

@nguyenduclong/mongodbts v1.0.24

Weekly downloads
-
License
ISC
Repository
github
Last release
3 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

3 years ago

1.0.23

3 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago