email/supplier/supplier.go

33 lines
771 B
Go
Raw Permalink Normal View History

2022-11-23 02:50:34 +00:00
package supplier
import (
"encoding/json"
"errors"
"git.selly.red/Selly-Modules/email/model"
"git.selly.red/Selly-Modules/email/utils"
"git.selly.red/Selly-Modules/natsio"
)
const (
SubjectCreateSupplierUser = "create_supplier_user"
)
func CreateSupplierUser(payload model.CreateSupplierUserEncrypt) (requestID string, err error) {
msg, err := natsio.GetServer().Request(SubjectCreateSupplierUser, utils.ToBytes(payload))
if err != nil {
return "", err
}
var res struct {
Data model.CreateSupplierUserResponse `json:"data"`
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &res); err != nil {
return "", err
}
if res.Error != "" {
return "", errors.New(res.Error)
}
return res.Data.RequestID, nil
}