how can i displaying a specific error in Joi? - joi

just a quick question I am suing Joi for validation and i wanna display a given error
departureDate: Joi.date().format('YYYY-MM-DD').error(() => ({
message: 'Date format must be YYYY-MM-DD'
})).min(moment().format('YYYY-MM-DD'))
.required()
.error(() => ({
message: 'No trips to the past'
})),
and the problem is that it's just displaying the last message even if I would put in a date format which is not correct

Because that is what the desirted behavior is. When you specify the custom error message it takes the last one. You can read more here.
The better solution is to upgrade your hapi and use .message or with existing version use .label

Related

ag-grid Refresh Column Filter after initial load

According to https://www.ag-grid.com/javascript-grid-filter-set/, "The grid does not update the filters for you as there are too many use cases...", #agreed.
I am using a Server Side data source with Infinite Paging querying a large set of data. Although, at initial load time, I may be confident the filter is listing all available "choices", I am hoping to find a solution to "reload" the filter at some frequency/event to be certain.
I am attempting to use the resetFilterValues() method of the object returned by a call to gridOptions.api.getFilterInstance(id).
When using a Server Side data source I am receiving the following console.error output:
ag-Grid: Set Filter cannot initialise because you are using a row model that does not contain all rows in the browser. Either use a different filter type, or configure Set Filter such that you provide it with values (Source ag-grid-enterprise.min.js:555
Note: The values method with async value load works splendidly and is written in accordance with recommendation e.g. callback to params.success with values.
I load the filter choices in the Column Header using the following approach:
{
headerName: 'Something',
field: 'SOMETHING',
width: 200,
suppressMenu: false,
suppressFilter: false,
filter: 'agSetColumnFilter',
filterParams: {
values: function (params) {
someAsyncMethodReturningAPIResultsAsArray();
}
newRowsAction: 'keep'
},
menuTabs: ['filterMenuTab']
}
I then attempt to reload the filters at a later time (like when a button is pressed outside the grid) using the following code:
var filter = gridOptions.api.getFilterInstance(id);
filter.resetFilterValues();
This code results in the error expressed above.
Q: Does anyone know how to configure Set Model to return rows as described in the error message? Is there a better way to approach this problem anyone has experience with?
Thanks
This code below can be executed in the postProcessPopup callback and it will call the values() function defined in filterParams every time the popup is opened
var filter = gridOptions.api.getFilterInstance(id);
filter.refreshFilterValues();
Note: The refreshFilterValues function is doing the trick here. It is available in v24 and above. Not too sure about older versions.

Dialogflow prebuilt agent's Make Appointment intent seems to be buggy on initial deployment

First, when you follow the tutorial here and deploy the recommended prebuilt agent, and you view the Inline Editor under fulfillment, the editor displays a warning/error on line 82:
expected an assignment or function call and instead saw an expression.
code snippet throwing up the error:
err ? reject(err) : resolve(event);
Having set up the Google Calender API and updated the parameter in index.js file, the prebuilt agent returns this error below when "Make Appointment intent" is run. the appointmentDateString constant can not read and parse the time parameter correctly.
Sorry, we're booked on Invalid Date at Invalid Date. Is there anything else I can do for you?
The problem is that the date format is not correct beacause there are two timeZoneOffset in the string to parse to Date.
In order to solve this issue, erase one of the timeoffset.
function convertParametersDate(date, time){
//ORIGINAL
//return new Date(Date.parse(date.split('T')[0] + 'T' + time.split('T')[1].split('-')[0] **+ timeZoneOffset**));
//SOLVED
return new Date(Date.parse(date.split('T')[0] + 'T' + time.split('T')[1].split('-')[0]));
}

Not able to pass complete datetime(Y-m-d H:i:s) in DB::raw in eloquent

$shop=DB::table('shops')
->leftJoin('orderbookings',function($join)
{
$join->on('shops.id','=','orderbookings.shop_id');
$join->on('orderbookings.created_at','>=',DB::raw(date("Y-m-d",strtotime("now"))));
})
->select('shops.*')
->selectRaw('COUNT(orderbookings.id) as totalorder, SUM(orderbookings.grand_total) as gtotal')
->orderBy('shops.shop_name', 'asc')
->groupby('shops.id')
->paginate(10);
Above code working fine(But not giving total order and amount correct) and also gives result almost close to what I want,
But I am not able to give date format (Y-m-d H:i:s), it shows syntax error. I am using Laravel 5.2 version
Note: I want to give time as well with date to rectify result,
On giving [example: 2017-03-08 11:15:00] shows syntax error
working query in mysql
SELECT COUNT(orderbookings.id), SUM(orderbookings.grand_total), shops.shop_name FROMshopsLEFT JOIN orderbookings on orderbookings.shop_id = shops.id and orderbookings.created_at BETWEEN "2015-10-22 17:02:02" AND "2017-03-07 17:02:02" GROUP BY shops.id
But not able to to convert in eloquent
You should be able to do the following:
$join->on('orderbookings.created_at', '>=', date("Y-m-d"));
You don't need to use DB::raw, and leaving the second parameter null for date, assumes "now".
If this doesn't solve your issue, please post the exact error you're seeing.

Running a query using date from a form MS Access

How do I run a query using a value from a textbox from a form I have? I know that there is another post here at Stackoverflow dealing with this issue but I found it to be insufficient for my needs.
I formated my textbox into Medium Date format with its default value being =Date(). However, when I pick up a date and open my report I get this error:
Runtime error 3071: Expression Too Complex
My where clause is this
WHERE
(
(AllInfo.DateOpened >= CDate([Forms]![Main Form]![WindowPrintOptions]![CustomizedReport]!txtDateOpenedFrom.Value))
)
and I am sure it is this code piece that is throwing the problem since when I take it out of the query the error message simply disappears.
Any ideas?
Try with:
(AllInfo.DateOpened >= DateValue([Forms]![Main Form]![WindowPrintOptions].[Form]!txtDateOpenedFrom))
)
Folks,
I got the problem. It was the "AllInfo" alias. It wasn't applicable at that escope inside the query. By changing the proper things, it was enough to write:
[Forms]![Main Form]![WindowPrintOptions]![CustomizedReport]!txtDateOpenedFrom.Value
Issue solved. Thank you all!

DBIx::Class undefined value exception when trying to use ->create()

I'm trying to create a new row using DBIx::Class from within Catalyst, with the following code:
$c->model('Session')->resultset('UserPreference')->create(
{
appname => 'rss_reader',
username => $username,
data => $data,
},
);
But, I hit this error every time:
Caught exception in App::Controller::rss->dbo "Can't call method "resolve" on an undefined value at /etg/source/Linux/pkg/perl-5.8.8/lib/site_perl/5.8.8/DBIx/Class/Row.pm line 1309."
I see a few mailing lists talking about this error being thrown as an incorrect blanket error when the query fails for whatever reason (perms, constraints,etc.), but it looks just fine AND even running with DBIC_TRACE=1, I don't even see the generated query in my console.
I should mention I don't think there's something bad with the permissions,etc. since using the database handle manually works:
my $stm=$c->model("Session")->storage->dbh->prepare("insert into user_preferences (username,appname,data) values ('mphillip','rss_reader','cookies')"); $stm->execute();
Have you tried update_or_create instead of create? If a row exists create will fail.