Skip to main content

User Employment Query Documentation

This code provides functions for querying and manipulating user employment data in the database. It uses the PocketBase DAO for database interactions and includes functions for inserting and updating user employment records.

Functions

InsertUserEmployment

func InsertUserEmployment(app core.App, dao *daos.Dao, req *entity.UserEmploymentTable) (*models.Record, error)

Inserts a new user employment record into the database.

  • app: The PocketBase app instance.
  • dao: The PocketBase DAO.
  • req: A pointer to a UserEmploymentTable struct containing the user employment data to be inserted.
  • Returns: A pointer to a models.Record containing the inserted record, or an error if the operation fails.

UpdateUserEmployment

func UpdateUserEmployment(app core.App, dao *daos.Dao, req *entity.UserEmploymentTable) (*models.Record, error)

Updates an existing user employment record in the database.

  • app: The PocketBase app instance.
  • dao: The PocketBase DAO.
  • req: A pointer to a UserEmploymentTable struct containing the updated user employment data.
  • Returns: A pointer to a models.Record containing the updated record, or an error if the operation fails.

Example Usage

Initializing the DAO

Before using the functions, you need to initialize the PocketBase DAO.

package main

import (
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
)

func main() {
// Initialize PocketBase
pb := pocketbase.New()

// Initialize the DAO
dao := daos.New(pb.DB())
}

Inserting a User Employment Record

package main

import (
"fio-backend/entity"
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/core"
"fmt"
)

func main() {
// Initialize PocketBase
pb := pocketbase.New()

// Initialize the DAO
dao := daos.New(pb.DB())

// Create a new user employment record
newUserEmployment := &entity.UserEmploymentTable{
UserProfileID: "user123",
CompanyID: "company123",
OfficeID: "office123",
BuildingID: "building123",
DepartmentID: "department123",
PositionID: "position123",
JoinedAt: "2023-01-01",
IsActive: true,
ContractType: entity.PERMANENT,
FileBase64ContractLetter: "base64-encoded-contract-letter",
}

// Insert the new user employment record
record, err := queries.InsertUserEmployment(pb, dao, newUserEmployment)
if err != nil {
fmt.Println("Error:", err)
return
}

fmt.Println("Inserted User Employment Record:", record)
}

Updating a User Employment Record

package main

import (
"fio-backend/entity"
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/core"
"fmt"
)

func main() {
// Initialize PocketBase
pb := pocketbase.New()

// Initialize the DAO
dao := daos.New(pb.DB())

// Retrieve the user employment record to update
userProfileID := "user123"
userEmployment, err := queries.GetUserEmployment(dao, userProfileID)
if err != nil {
fmt.Println("Error:", err)
return
}

// Update the user employment record fields
userEmployment.PositionID = "new_position123"
userEmployment.ContractType = entity.TEMPORARY
userEmployment.FileBase64ContractLetter = "new-base64-encoded-contract-letter"

// Update the user employment record in the database
updatedRecord, err := queries.UpdateUserEmployment(pb, dao, userEmployment)
if err != nil {
fmt.Println("Error:", err)
return
}

fmt.Println("Updated User Employment Record:", updatedRecord)
}

This documentation provides an overview of the user employment query functions, their parameters, and example usage. By following the examples, you can insert and update user employment records in the database.