Capstone/ui/db/models/vendor.go

45 lines
962 B
Go
Raw Normal View History

2023-10-30 20:06:18 -04:00
package models
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
2023-10-30 20:06:18 -04:00
const VENDOR_ACCOUNT_TYPE = "vendor_account"
2023-11-02 19:23:07 -04:00
const (
2023-11-04 23:43:01 -04:00
YOUTUBE_VENDOR_NAME = "youtube"
PCO_VENDOR_NAME = "pco"
2023-11-02 19:23:07 -04:00
)
2023-10-30 20:06:18 -04:00
type VendorAccount struct {
*CommonFields `bson:"obj_info"`
Id primitive.ObjectID `bson:"_id,omitempty"`
UserId primitive.ObjectID `bson:"user_id,omitempty"`
Secret string `bson:"secret,omitempty"`
OauthCredentials *OauthCredential `bson:"ouath_credentials,omitempty"`
2023-11-02 19:23:07 -04:00
Name string `bson:"name"`
}
func (va *VendorAccount) MongoId() primitive.ObjectID {
if va.Id.IsZero() {
now := time.Now()
va.Id = primitive.NewObjectIDFromTimestamp(now)
}
return va.Id
}
func (va *VendorAccount) UpdateObjectInfo() {
now := time.Now()
if va.CommonFields == nil {
va.CommonFields = new(CommonFields)
va.EntityType = VENDOR_ACCOUNT_TYPE
va.CreatedAt = now
}
va.UpdatedAt = now
2023-10-30 20:06:18 -04:00
}