How do I set timeout for LocalNotification - ionic-framework

How do I set timeout like example I want the notification to be
Trigger start from (27 Nov 2020, 12pm)
Subsequently every one hour until 28 Nov 2020, 12pm.
Without reopening the app, heres my codes.
var mySchedule: LocalNotificationSchedule = {
on:"27 Nov 2020, 12pm",
repeats: true,
every: 'hour',
count:1,
#until : "28 Nov 2020, 12pm"
};
var notification={};
notification["title"]="Local Notification Test";
notification["body"]="Example body";
notification["id"]="2";
notification["schedule"]=mySchedule;
notification["sound"]="default";
this.localNoti.push(notification);
const notifs = await LocalNotifications.schedule({
notifications: this.localNoti
});

Related

GraphQL : Auto renew is creating duplicates

I have created a MERN employee management system where employers can assign task to employees have it able to change status(pending, overdue and submitted). And created recurring tasks which renew everyday automatically
So the idea is to create a resolver, which finds all Tasks. Once all tasks are found, it needs to check if any are over due and set the status of the task to overdue and the look for recurring Tasks
Recurring tasks are to renew automatically when the due date of the task has reached
I was Successful in achieving this but now for some reason the tasks are duplicating
i.e., if there is task
Expected
"send sales report" due on 24th mar 2022
so when it renews for the next day it should be
"send sales report" due on 25th mar 2022
But it duplicates
Current
"send sales report" due on 24th mar 2022
so when it renews for the next day it is
"send sales report" due on 25th mar 2022
"send sales report" due on 25th mar 2022
Sometimes it is creating duplicates, sometime it is creating triplets and some times quadruples
Attaching resolver below.
tasks : async () => {
const today = new Date()
const todayunix = Date.parse(today)
const allTasks = await Task.find({}).populate('user').sort({ status: 1 });
const recuurringTask = allTasks.filter((task)=> task.recurring === true)
const checkStatus = allTasks.filter((task) => task.status === 'pending')
if (today.getDay() !== 1) {
for (let i = 0; i < checkStatus.length; i++){
if(checkStatus[i].dueDate < todayunix){
const overdue = await Task.findByIdAndUpdate({_id : checkStatus[i]._id},{status:'overdue'})
}
}
for(let i = 0; i < recuurringTask.length; i++){
const fDueDate= new Date(recuurringTask[i].dueDate)
const fDueDateUnix = Date.parse(fDueDate)
if(fDueDateUnix < todayunix) {
const dueInDays = 86400000 * recuurringTask[i].renewIn
const calcDueDate = dueInDays + todayunix
const task = {
description: recuurringTask[i].description,
user: recuurringTask[i].user,
dueDate: new Date(calcDueDate),
recurring: recuurringTask[i].recurring,
renewIn:recuurringTask[i].renewIn
};
const createTask = await Task.create(task)
const setRecurringFalse = await Task.findOneAndUpdate({_id:recuurringTask[i]._id},{recurring:false})
}
}
}
return allTasks
},

Why subsequent tests for ngmocke2e failed to call mock backend. Only the first test would pass. Second test would call the real backend

Why subsequent tests for ngmocke2e failed to call mock backend? Only the first test would pass. Second test would call the real backend.
Here is my sample code: The first test would call the mock. The second will call the real backend.
var LoginPage = require( './login_page' );
describe('As a user, when using valid credentials', function() {
var login = new LoginPage();
beforeEach(
function () {
browser.addMockModule('myService', function() {
angular
.module('myService', ['myApp', 'ngMockE2E'])
.run(function($httpBackend) {
var access={"access_token":"a", "token_type":"bearer", "expires_in":299, "refresh_token":"a", "userName":"any", "clientId":"blah", ".issued":"Mon, 08 Jun 2015 20:47:40 GMT", ".expires":"Mon, 08 Jun 2015 20:52:40 GMT"};
$httpBackend.whenPOST("https://blah.com/OAuth2Server/1.0/OAuth/Token").respond(200, access);
$httpBackend.whenGET(/\/*/).passThrough();
$httpBackend.whenPOST().passThrough();
});
});
});
it('logins successfully', function() {
login
.navigate()
.login("anything", "password");
browser.sleep(5000);
browser.ignoreSynchronization=true;
var currentUrl=browser.getCurrentUrl();
expect(currentUrl).toBe("http://localhost:55555/#/my-jobs");
});
});
describe('As a user, when using valid credentials', function() {
var login = new LoginPage();
beforeEach(
function () {
browser.addMockModule('myService', function() {
angular
.module('myService', ['myApp', 'ngMockE2E'])
.run(function($httpBackend) {
var access={"access_token":"a", "token_type":"bearer", "expires_in":299, "refresh_token":"a", "userName":"any", "clientId":"blah", ".issued":"Mon, 08 Jun 2015 20:47:40 GMT", ".expires":"Mon, 08 Jun 2015 20:52:40 GMT"};
$httpBackend.whenPOST("https://blah.com/OAuth2Server/1.0/OAuth/Token").respond(200, access);
$httpBackend.whenGET(/\/*/).passThrough();
$httpBackend.whenPOST().passThrough();
});
});
});
it('logins successfully', function() {
login
.navigate()
.login("anything2", "password2");
browser.sleep(5000);
browser.ignoreSynchronization=true;
var currentUrl=browser.getCurrentUrl();
expect(currentUrl).toBe("http://localhost:55555/#/my-jobs");
});
});
I don't exactly know why this issue occurs (happened to me as well), but I was able to 'fix' it by restarting the browser at the end each describe. Just reloading it didn't work for me.
Add the following inside each describe:
afterAll(function() {
// need this to avoid problems with ngmocke2e
browser.restart();
});
I know it's not an ideal solution, and it adds some extra time to the tests, but this does the trick for now.

why don't I get anything returned from mongo with this jugglingdb query

I am using compoundjs with jugglingdb to get some data from Mongo.
in my code I have the following
Hotspot.all({ where : { fromid : imageMappingWidget.id } },
function (err, hotspots) {
console.log(hotspots);
for (i in hotspots) {
var hotspot = hotspots[i];
hotspot.destroy();
console.log("removed" + hotspot);
};
});
the console.log of hotspots outputs an empty array, and I of course never get in to the loop.
My imageMappingWidget object is
{ schema_version: 1,
name: 'Testing 2',
image: null,
width: '3264',
height: '2448',
createDate: Sun Aug 24 2014 14:27:56 GMT+0200 (CEST),
updateDate: Sun Aug 24 2014 14:27:56 GMT+0200 (CEST),
uploadedImage: true,
requiredWidth: null,
id: 53f9da4c1ef48ced2a000001}
However if I do the following query from mongo on the command line
db.Hotspot.find({ fromid: "53f9da4c1ef48ced2a000001"})
I get exactly one record back.
I thought, immediately after asking - why don't I just try to see if tostring on the id will help, and it did.
grrrr.

WARNING Error: Meteor code must always run within a Fiber when call method on server

I'm trying to deploy my meteor app onto the server but it always has this error on my meteor server log
Fri Jun 21 2013 11:39:31 GMT+0000 (UTC)] INFO HIT /img/bg.png
183.90.41.21 [Fri Jun 21 2013 11:39:32 GMT+0000 (UTC)] INFO HIT /favicon.ico 183.90.41.21 [Fri Jun 21 2013 11:39:41 GMT+0000 (UTC)] INFO HIT /form 183.90.41.21 [Fri Jun 21 2013 11:39:42 GMT+0000 (UTC)] INFO HIT /favicon.ico 183.90.41.21 [Fri Jun 21 2013 11:39:49 GMT+0000 (UTC)] WARNING }).run();
^ [Fri Jun 21 2013 11:39:49 GMT+0000 (UTC)] WARNING app/server/server.js:53 [Fri Jun 21 2013 11:39:49 GMT+0000 (UTC)] WARNING Error: Meteor code must always run within a Fiber
at _.extend.get (app/packages/meteor/dynamics_nodejs.js:14:13)
at _.extend.apply (app/packages/livedata/livedata_server.js:1268:57)
at _.extend.call (app/packages/livedata/livedata_server.js:1229:17)
at Meteor.startup.Meteor.methods.streamTwit (app/server/server.js:51:22)
but I have already wrapped it within Fiber and it works well locally. I really do not know what could be the problem. Appreciate if anyone can help.
//server.js
Meteor.startup(function () {
var require = Npm.require;
var fs = require('fs');
var path = require('path');
var base = path.resolve('.');
var isBundle = fs.existsSync(base + '/bundle');
var modulePath = base + (isBundle ? '/bundle/static' : '/public') + '/node_modules';
var ntwitter = require(modulePath + '/ntwitter');
var Fiber = require(modulePath + '/fibers');
var twit = new ntwitter({
consumer_key: 'my key',
consumer_secret: 'my key',
access_token_key: 'my key',
access_token_secret: 'my key'
});
Meteor.methods({
postText : function(questionText){
twit.verifyCredentials(function (err, data) {
if (err) {
console.log("Error verifying credentials: " + err);
process.exit(1);
}
}).updateStatus(questionText,
function (err, data) {
if (err) {
console.log('Tweeting failed: ' + err);
return false;
}
else {
console.log('Success!');
return true;
}
}
);
},
streamTwit: function (twit){
var userid = '1527228696';
twit.stream(
'statuses/filter',
{ follow: userid},
function(stream) {
stream.on('data', function(tweet) {
Fiber(function(){
if(tweet.user.id_str === userid)
{
Meteor.call('addQn', tweet);
}
}).run();
console.log('----------------------tracking tweet-----------------');
console.log(tweet);
console.log('---------------------------------------------------------');
console.log(tweet.user.screen_name);
console.log(tweet.user.name);
console.log(tweet.text);
});
}
);
},
addQn:function(tweet){
questionDB.insert({'tweet': tweet, 'date': new Date()});
}
});
Fiber(function(){
Meteor.call('streamTwit', twit);
}).run();
});
PS:I've replace my OAuth key. Thanks in advance
i think you should wrap your callbacks with Meteor.bindEnvironment rather than use fibers directly - see here https://gist.github.com/possibilities/3443021
i use this quite extensively and it works well because you stay within the fiber rather than leaving and having to re-enter
normal callback style
someMethod({OPTIONS}, function(callbackReturnArgs){
//this is the normal callback
));
bind environment wrapped callback
someMethod({OPTIONS}, Meteor.bindEnvironment(
function(callbackReturnArgs){
//this is the normal callback
},
function(e){
console.log('bind failure');
}
));
if you consistently wrap async callbacks like this, meteor is always accessbile
for this bit here
Fiber(function(){
Meteor.call('streamTwit', twit);
}).run();
you do not need to fiber wrap this, you are already in the Meteor.startup context, so this is redundant - just the Meteor.call(...); will do the trick

Javascript GMT string convert to Local Time

$(function() {
$('#datepicker').datepick({
multiSelect: 999,
monthsToShow: 3,
minDate: new Date(),
maxDate: '+1y',
showTrigger: '#calImg',
dateFormat: 'yy-mm-dd',
onSelect: function(value) {
alert(value);
}
});
});
this code block returns a string like that "Wed Jan 11 2012 12:00:00 GMT+0100".
How can I convert that string like that "2012-01-11 12:00:00"?
You can use this to covert to local time and get rid of GMT
function getLocalTimeFromGMT(sTime){
var dte = new Date(sTime);
dte.setTime(dte.getTime() - dte.getTimezoneOffset()*60*1000);
document.write(dte.toLocaleString()); }
cf http://teck.in/indian-standard-time-and-gmt-from.html#ixzz1hNGiQAhg