Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create examples sub-project for something like plugin testing / showcase #734

Open
2 of 3 tasks
hasezoey opened this issue Jul 3, 2022 · 4 comments
Open
2 of 3 tasks
Labels
docs This issue is about Documentation feature Adds a new Feature or Request

Comments

@hasezoey
Copy link
Member

hasezoey commented Jul 3, 2022

Describe what you need | want

Currently typegoose only has plugin testing with some specific plugins and the examples in the documentation are also not tested / updated, so i would propose to add a examples sub-project which houses full-working examples of either typegoose itself and / or with plugins

Do you have already an idea for the implementation?

see above


Plugins to maybe consider adding initially:

@hasezoey hasezoey added feature Adds a new Feature or Request docs This issue is about Documentation labels Jul 3, 2022
@hmz22
Copy link

hmz22 commented Aug 1, 2022

How can add plugin in my code?
for paginate I do this:

type PaginateMethod<T> = (
  query?: FilterQuery<T>,
  options?: PaginateOptions,
  callback?: (err: any, result: PaginateResult<T>) => void
) => Promise<PaginateResult<T>>;

type AggregatePaginateMethod<T> = (
  query?: Aggregate<T[]>,
  options?: PaginateOptions,
  callback?: (err: any, result: AggregatePaginateResult<T>) => void
) => Promise<AggregatePaginateResult<T>>;

@Plugins(paginate)
@Plugins(aggregatePaginate)
@Plugins(MongooseDelete, {
  overrideMethods: "all",
  deletedAt: true,
  deletedBy: true,
})
export class BasicModel {
  static paginate: PaginateMethod<typeof BasicModel>;
  static aggregatePaginate: AggregatePaginateMethod<typeof BasicModel>;
}

but for mongoose-delete I don't know how do this?

I make:

import MongooseDelete, { SoftDeleteModel } from "mongoose-delete";

export type ISoftDeleteModel<T, T2> = SoftDeleteModel<DocumentType<T>> & T & T2;

and use other module:

// any idea for add to base class?
import { BasicModel, ISoftDeleteModel } from "../base.model";

@ObjectType()
export class Member extends BasicModel {
  @Field(() => GraphQLObjectID)
  _id!: string;

  @Field({ nullable: true })
  @Property()
  firstname?: string;

  @Field()
  @Property()
  lastname?: string;
}

@ObjectType()
export class MemberData {
  @Field(() => [Member])
  docs?: Member[];
}

export const MemberModel = getModelForClass(Member, {
  existingConnection: publicConnection,
  schemaOptions: {
    timestamps: true,
    collection: "members",
  },
}) as ISoftDeleteModel<Member, typeof Member>;

any idea for add to base class?

@hasezoey
Copy link
Member Author

hasezoey commented Aug 1, 2022

@hmz22 such a case (a plugin with custom model / document types) is definitely a thing i would like to add as a example, but this is not really the correct place to ask for this, the more correct place would be in discussions, also i dont really understand your question, please be more specific in what you want to achieve.

@hmz22
Copy link

hmz22 commented Aug 1, 2022

mongoose-delete have Method overridden like countDeleted,... and when I use MemberMode.countDeleted type script show error this model haven't countDeleted and I must add as ISoftDeleteModel<Member, typeof Member> any model to access IntelliSense

@hasezoey
Copy link
Member Author

i have created a repository: https://github.com/typegoose/typegoose-examples (it will not be a sub-directory)

anyone can suggest packages or other case examples to add or submit a PR for examples (follow CONTRIBUTING and the root README)

PS: will keep this issue open until some more examples are in the repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is about Documentation feature Adds a new Feature or Request
Projects
None yet
Development

No branches or pull requests

2 participants