remove source

This commit is contained in:
Nam Huynh 2021-08-17 15:54:06 +07:00
parent 3af9a2a41a
commit ae9b4cd9c4
6 changed files with 4 additions and 17 deletions

View File

@ -29,7 +29,6 @@ func (s Service) Create(payload CreatePayload) {
// Get document // Get document
doc := Audit{ doc := Audit{
ID: mongodb.NewObjectID(), ID: mongodb.NewObjectID(),
Source: s.Source,
Target: payload.Target, Target: payload.Target,
TargetID: payload.TargetID, TargetID: payload.TargetID,
Action: payload.Action, Action: payload.Action,

View File

@ -26,7 +26,6 @@ func (s Service) All(query AllQuery) []Audit {
// Find db // Find db
cursor, err := s.DB.Collection(colName).Find(ctx, bson.D{ cursor, err := s.DB.Collection(colName).Find(ctx, bson.D{
{"source", s.Source},
{"target", query.Target}, {"target", query.Target},
{"targetId", query.TargetID}, {"targetId", query.TargetID},
}, &options.FindOptions{ }, &options.FindOptions{

View File

@ -15,8 +15,6 @@ type MongoDBConfig struct {
// Config ... // Config ...
type Config struct { type Config struct {
// Source of server, e.g: selly
Source string
// Targets: staff, article, ... // Targets: staff, article, ...
Targets []string Targets []string
// MongoDB config, for save documents // MongoDB config, for save documents
@ -33,8 +31,8 @@ var s *Service
// NewInstance ... // NewInstance ...
func NewInstance(config Config) error { func NewInstance(config Config) error {
if config.Source == "" || len(config.Targets) == 0 || config.MongoDB.Host == "" { if len(config.Targets) == 0 || config.MongoDB.Host == "" {
return errors.New("please provide all necessary information: source, targets, mongodb") return errors.New("please provide all necessary information: targets, mongodb")
} }
// Connect MongoDB // Connect MongoDB

View File

@ -1,8 +0,0 @@
package audit
// List actions
const (
ActionCreate = "create"
ActionUpdate = "update"
ActionUpdatePermissions = "update-permissions"
)

View File

@ -6,9 +6,9 @@ import (
func (s Service) indexDB() { func (s Service) indexDB() {
// Index key // Index key
commonIndex := mongodb.NewIndexKey("source", "target", "targetId") commonIndex := mongodb.NewIndexKey("target", "targetId")
// Index all allowed sources // Index all targets
for _, target := range s.Targets { for _, target := range s.Targets {
mongodb.CreateIndex(getColName(target), commonIndex) mongodb.CreateIndex(getColName(target), commonIndex)
} }

View File

@ -9,7 +9,6 @@ import (
// Audit ... // Audit ...
type Audit struct { type Audit struct {
ID primitive.ObjectID `bson:"_id" json:"id"` ID primitive.ObjectID `bson:"_id" json:"id"`
Source string `bson:"source" json:"source"`
Target string `bson:"target" json:"target"` Target string `bson:"target" json:"target"`
TargetID string `bson:"targetId" json:"targetId"` TargetID string `bson:"targetId" json:"targetId"`
Action string `bson:"action" json:"action"` Action string `bson:"action" json:"action"`