Capstone/ui/db/vendors.go

30 lines
767 B
Go
Raw Normal View History

2023-10-31 21:31:26 -04:00
package db
import (
"context"
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/config"
"git.preston-baxter.com/Preston_PLB/capstone/frontend-service/db/models"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
func (db *DB) FindVendorAccountByUser(userId string) ([]models.VendorAccount, error){
conf := config.Config()
opts := options.Find()
res, err := db.client.Database(conf.Mongo.EntDb).Collection(conf.Mongo.EntCol).Find(context.Background(), bson.M{"user_id": userId, "obj_info.ent": models.VENDOR_ACCOUNT_TYPE}, opts)
if err != nil {
return nil, err
}
vendors := []models.VendorAccount{}
err = res.All(context.Background(), vendors)
if err != nil {
return nil, err
}
return vendors, nil
}