package Daje::Controller::Companies::CompaniesLoad;
use Mojo::Base 'Mojolicious::Controller', -base, -signatures;
use v5.42;

# NAME
# ====
#
# Daje::Controller::CompaniesUsersList - Model class
#
# SYNOPSIS
# ========
#
#       use Daje::Controller::Companies::CompaniesUsersList;
#
#
#
# DESCRIPTION
# ===========
#
# Daje::Controller::Companies::vCompaniesUsersList is a standard controller
#
# METHODS
# =======
#
#
# LICENSE
# =======
#
# Copyright (C) janeskil1525.
#
# This library is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
# AUTHOR
# ======
#
# janeskil1525 E<lt>janeskil1525@gmail.com
#

# This file is generated automatically by Daje Tools 2026-02-02 15:02:14.
# It will not be re-generated by Daje Tools again.
# <!-- Autogenerated file 2026-02-02 15:02:14 -->

use Mojo::JSON qw{from_json};
use Data::Dumper;

our $VERSION = '0.01';


sub load_all_companies_for_user($self) {

    $self->app->log->debug('Daje::Controller::Companies::CompaniesLoad::load_all_companies_for_user start ');
    $self->render_later;

    my ($companies_pkey, $users_pkey) = $self->jwt->companies_users_pkey(
        $self->req->headers->header('X-Token-Check')
    );
    my $data = from_json($self->req->body);

    $self->companies->load_companies_from_user_mail_p($data->{mail})->then(sub($result) {
        $self->render(json => { result => 'success', data => $result });
    })->catch(sub($err) {
        $self->app->log->error('Daje::Controller::Companies::CompaniesLoad ' . $err);
        $self->render(json => {result => 'failed', data => $err});
    });
    $self->app->log->debug('Daje::Controller::Companies::CompaniesLoad::load_all_companies_for_user end ');
}


1;

