barcodebuddy icon indicating copy to clipboard operation
barcodebuddy copied to clipboard

Feature Request: Chores, execute a chore done_by specific user ; multiple barcode per chores

Open alex-devg opened this issue 2 years ago • 0 comments

From the "Chores" menu it would be nice to have the possibility to assign more than one barcode per chores, making it possible to specify the User who execute the chore

Grocy API have the possibility to specify which user did the chore

Request body

{
  "tracked_time": "",
  "done_by": 2,
  "skipped": false
}

I could quickly make it work with a few changes on incl/processing.inc.php and incl/api.inc.php and the structure of the table barcodebuddy.db/ChoreBarcode

It seams to work, but didn't do any proper testing, and writing this I can already see a problem if the choreUserId is null.

I didn't check the UI, I made all changes in the DB manually, finding userIDs as well, I don't know how much work it would be to catch all users from Grocy to be able to assign each barcode to a user on the UI

SQL
CREATE TABLE ChoreBarcodes(
       id INTEGER PRIMARY KEY, 
       choreId INTEGER , #not unique anymore
       barcode TEXT NOT NULL , #shoudn't it be unique btw?
       choreUserId INTEGER #new column
);
incl/processing.inc.php
/**
 * Execute a chore when chore barcode was submitted
 * @param string $barcode Barcode
 * @return mixed
 * @throws DbConnectionDuringEstablishException
 */
function processChoreBarcode(string $barcode) {
        if (ChoreManager::isGrocyCode($barcode)){
                $userId = 0;
                $id = ChoreManager::getIdFromGrocyCode($barcode);
        }
        else {
            $row = ChoreManager::getChoreBarcode(sanitizeString($barcode));
            $id = $row['choreId'];
            $userId = $row['choreUserId'];
        }       
        $id = checkIfNumeric($id);
        API::executeChore($id, $userId);

        return sanitizeString(API::getChoreInfo($id)["name"]);
}
incl/processing.inc.php
    /**
     * Executes a Grocy chore
     *
     * @param int $choreId
     *
     * @return void
     */
    public static function executeChore(int $choreId, int $choreUserId = 0): void {

        $url  = API_CHORE_EXECUTE . $choreId . "/execute";
        $data = json_encode(array(
            'tracked_time' => "",
            'done_by'      => $choreUserId 
        ));

        $curl = new CurlGenerator($url, METHOD_POST, $data);
        try {
            $curl->execute(true);
        } catch (Exception $e) {
            self::processError($e, "Could not execute chore");
        }
    }

alex-devg avatar Jun 05 '22 13:06 alex-devg