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
doc := Audit{
ID: mongodb.NewObjectID(),
Source: s.Source,
Target: payload.Target,
TargetID: payload.TargetID,
Action: payload.Action,

View File

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

View File

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

View File

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