Michelle Carter, please share the entire code snippet.
import {Injectable} from '@angular/core';
import {SqlService} from "./sql.service";
import {Subscriptions} from '../models/subscriptions';
import {Platform/*, Events*/ } from '@ionic/angular';
import {Events} from './events.service';
import {UserServiceService} from './user-service.service';
/*import { BackgroundMode } from 'ionic-native';*/
import {ModelsServiceService} from './models-service.service';
import {User} from '../models/user';
import {UpdateNewProviderService} from "./update-new-provider.service";
import {LogProviderService} from "./log-provider.service";
import { HTTP } from '@ionic-native/http/ngx';
import {LoginProviderService} from "./login-provider.service";
import { Device } from '@ionic-native/device/ngx';
//BackgroundMode.enable();
@Injectable({
providedIn: 'root'
})
export class SubscriptionsServiceService {
//storage:Storage = null;
//products:Array<Object>;
products:any;
public count = 0;
public output;
public checksubscription: string;
constructor(
private sql: SqlService,
public platform: Platform,
public updateNewProvider: UpdateNewProviderService,
public userService: UserServiceService,
public logProvider: LogProviderService,
public http: HTTP,
public events: Events,
private device: Device,
public loginProvider: LoginProviderService,
public modelService: ModelsServiceService
) {
this.products = [];
// this.storage = new Storage();
this.platform.ready().then(() => {
this.checksubscription = this.loginProvider.rootUrl + 'checksubscription.php';
});
}
addSubscription(subsc: Subscriptions){
console.log("subsc",subsc);
let save = 'INSERT INTO subscription (user_id, external_id, description, active, url,work_order,bu_url,iu_url,bu_url_local_path,iu_url_local_path,mu_url,mu_url_local_path,sc,server_date,date_warning,date_auth,run_warning_message,run_warning_message_time,update_method,iurl,murl,rurl,ua,status,pi,ms) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
console.log(save ,[subsc.user_id, subsc.external_id, subsc.description, subsc.active, subsc.url]);
return this.sql.query(save, [subsc.user_id, subsc.external_id, subsc.description, subsc.active,
subsc.url,subsc.work_order,subsc.bu_url,subsc.iu_url,subsc.bu_url_local_path,subsc.iu_url_local_path,
subsc.mu_url,subsc.mu_url_local_path,subsc.sc,
subsc.server_date,subsc.date_warning,subsc.date_auth,subsc.run_warning_message,subsc.run_warning_message_time,subsc.update_method,subsc.iurl,subsc.murl, subsc.rurl, subsc.ua, subsc.status, subsc.pi, subsc.ms]);
}
addNewSubscription(subsc: Subscriptions):Promise<any>{
return new Promise((resolve,reject)=>{
console.log("addNewSubscription", subsc);
this.selectCurrentSubscription(subsc).then(d=>{
if (undefined !== d) {
if (d.res.rows.length>0)
{
let save = 'UPDATE subscription SET description =?, active =?, url =?, work_order=?,bu_url=?,iu_url=?,bu_url_local_path=?,iu_url_local_path=?,mu_url=?,mu_url_local_path=?,sc=?,server_date=?,date_warning=?,date_auth=?,run_warning_message=?,run_warning_message_time=?,update_method=?,iurl=?,murl=?, rurl=?, ua=?, status=?, pi=?, ms=? WHERE user_id=? AND external_id= ?';
this.sql.query(save ,[subsc.user_id, subsc.external_id, subsc.description, subsc.active,
subsc.url,subsc.work_order,subsc.bu_url,subsc.iu_url,subsc.bu_url_local_path,subsc.iu_url_local_path,
subsc.mu_url,subsc.mu_url_local_path,subsc.sc,
subsc.server_date,subsc.date_warning,subsc.date_auth,subsc.run_warning_message,subsc.run_warning_message_time, subsc.update_method,subsc.iurl,subsc.murl, subsc.rurl, subsc.ua, subsc.status, subsc.pi, subsc.ms]).then(() => {
//console.log(save ,[subsc.description,subsc.active,subsc.url,subsc.work_order,subsc.bu_url,subsc.iu_url,subsc.user_id, subsc.external_id]);
resolve(true);
//}).catch(err =>{reject(err)});
}).catch(err => {
console.log("err catch",err);
reject(err);
});
}
else
{
let save = 'INSERT INTO subscription (user_id, external_id, description, active, url,work_order,bu_url,iu_url,bu_url_local_path,iu_url_local_path,mu_url,mu_url_local_path,sc,server_date,date_warning,date_auth,run_warning_message,run_warning_message_time,update_method,iurl,murl,ua,status,pi,ms) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
this.sql.query(save,[subsc.user_id, subsc.external_id, subsc.description, subsc.active,
subsc.url,subsc.work_order,subsc.bu_url,subsc.iu_url,subsc.bu_url_local_path,subsc.iu_url_local_path,
subsc.mu_url,subsc.mu_url_local_path,subsc.sc,
subsc.server_date,subsc.date_warning,subsc.date_auth,subsc.run_warning_message,subsc.run_warning_message_time,subsc.update_method,subsc.iurl,subsc.murl, subsc.ua, subsc.status, subsc.pi, subsc.ms]).then(()=>{
/* console.log(save ,[subsc.user_id, subsc.external_id, subsc.description, subsc.active,
subsc.url,subsc.work_order,subsc.bu_url,subsc.iu_url,subsc.bu_url_local_path,subsc.iu_url_local_path]);*/
resolve(true);
//}).catch(err=>{reject(err)});
}).catch(err => {
console.log("err catch",err);
reject(err);
});
}
}
});
});
}
}