Skip to content

Commit 3543b57

Browse files
fix(callback): add missing model hook on InitializeCallbacks() (#97)
1 parent b2df4a6 commit 3543b57

File tree

1 file changed

+76
-7
lines changed

1 file changed

+76
-7
lines changed

callback/callback.go

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package callback
1717
import (
1818
"context"
1919

20+
"github.com/chenmingyong0423/go-mongox/v2/internal/hook/model"
21+
2022
"github.com/chenmingyong0423/go-mongox/v2/internal/hook/field"
2123

2224
"github.com/chenmingyong0423/go-mongox/v2/operation"
@@ -33,30 +35,97 @@ func InitializeCallbacks() *Callback {
3335
return field.Execute(ctx, opCtx, operation.OpTypeBeforeInsert, opts...)
3436
},
3537
},
38+
{
39+
name: "mongox:model",
40+
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
41+
return model.Execute(ctx, opCtx, operation.OpTypeBeforeInsert, opts...)
42+
},
43+
},
44+
},
45+
afterInsert: []callbackHandler{
46+
{
47+
name: "mongox:model",
48+
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
49+
return model.Execute(ctx, opCtx, operation.OpTypeAfterInsert, opts...)
50+
},
51+
},
3652
},
37-
afterInsert: make([]callbackHandler, 0),
3853
beforeUpdate: []callbackHandler{
3954
{
4055
name: "mongox:fieds",
4156
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
4257
return field.Execute(ctx, opCtx, operation.OpTypeBeforeUpdate, opts...)
4358
},
4459
},
60+
{
61+
name: "mongox:model",
62+
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
63+
return model.Execute(ctx, opCtx, operation.OpTypeBeforeUpdate, opts...)
64+
},
65+
},
66+
},
67+
afterUpdate: []callbackHandler{
68+
{
69+
name: "mongox:model",
70+
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
71+
return model.Execute(ctx, opCtx, operation.OpTypeAfterUpdate, opts...)
72+
},
73+
},
74+
},
75+
beforeDelete: []callbackHandler{
76+
{
77+
name: "mongox:model",
78+
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
79+
return model.Execute(ctx, opCtx, operation.OpTypeBeforeDelete, opts...)
80+
},
81+
},
82+
},
83+
afterDelete: []callbackHandler{
84+
{
85+
name: "mongox:model",
86+
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
87+
return model.Execute(ctx, opCtx, operation.OpTypeAfterDelete, opts...)
88+
},
89+
},
4590
},
46-
afterUpdate: make([]callbackHandler, 0),
47-
beforeDelete: make([]callbackHandler, 0),
48-
afterDelete: make([]callbackHandler, 0),
4991
beforeUpsert: []callbackHandler{
5092
{
5193
name: "mongox:fieds",
5294
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
5395
return field.Execute(ctx, opCtx, operation.OpTypeBeforeUpsert, opts...)
5496
},
5597
},
98+
{
99+
name: "mongox:model",
100+
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
101+
return model.Execute(ctx, opCtx, operation.OpTypeBeforeUpsert, opts...)
102+
},
103+
},
104+
},
105+
afterUpsert: []callbackHandler{
106+
{
107+
name: "mongox:model",
108+
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
109+
return model.Execute(ctx, opCtx, operation.OpTypeAfterUpsert, opts...)
110+
},
111+
},
112+
},
113+
beforeFind: []callbackHandler{
114+
{
115+
name: "mongox:model",
116+
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
117+
return model.Execute(ctx, opCtx, operation.OpTypeBeforeFind, opts...)
118+
},
119+
},
120+
},
121+
afterFind: []callbackHandler{
122+
{
123+
name: "mongox:model",
124+
fn: func(ctx context.Context, opCtx *operation.OpContext, opts ...any) error {
125+
return model.Execute(ctx, opCtx, operation.OpTypeAfterFind, opts...)
126+
},
127+
},
56128
},
57-
afterUpsert: make([]callbackHandler, 0),
58-
beforeFind: make([]callbackHandler, 0),
59-
afterFind: make([]callbackHandler, 0),
60129
}
61130
}
62131

0 commit comments

Comments
 (0)