我需要一些帮助在mongodb和nodejs中按日期查找记录.
我在抓取脚本中将日期添加到json对象,如下所示:
jsonObj.last_updated = new Date();
Run Code Online (Sandbox Code Playgroud)
该对象插入到mongodb中.我可以看到如下:
"last_updated" : "2014-01-22T14:56:59.301Z"
Run Code Online (Sandbox Code Playgroud)
然后在我的nodejs脚本中我做了一个findOne():
var jObj = JSON.parse(line.toString());
collection.findOne(jObj,function(err, doc) {
if (doc){
console.log(doc._id);
} else {
console.log('not found');
}
});
Run Code Online (Sandbox Code Playgroud)
找不到该对象.如果我从对象中删除了last_updated字段,那么它就是问题所在.
如果我按如下方式隔离该字段:
collection.findOne({last_updated: '2014-01-22T14:56:59.301Z'},function(err, doc) {
if (doc){
console.log(doc._id);
} else {
console.log('not found');
}
});
Run Code Online (Sandbox Code Playgroud)
什么都没有回来.我做错了什么?
我在Express中有以下内容
//index.js
var service = require('./subscription.service');
var auth = require('../auth/auth.service');
var router = express.Router();
router.post('/sync', auth.isAuthenticated, service.synchronise);
module.exports = router;
Run Code Online (Sandbox Code Playgroud)
我想覆盖或模拟isAuthenticated返回此
auth.isAuthenticated = function(req, res, next) {
return next();
}
Run Code Online (Sandbox Code Playgroud)
这是我的单元测试:
it('it should return a 200 response', function(done) {
//proxyquire here?
request(app).post('/subscriptions/sync')
.set('Authorization','Bearer '+ authToken)
.send({receipt: newSubscriptionReceipt })
.expect(200,done);
});
Run Code Online (Sandbox Code Playgroud)
我尝试使用proxyquire模拟index.js - 我想我需要存根路由器?我也试过在测试中覆盖
app.use('/subscriptions', require('./api/subscription'));
Run Code Online (Sandbox Code Playgroud)
必须有一种简单的方法来模拟它,所以我不需要验证请求.有任何想法吗?
我需要使用节点对Firebase用户进行身份验证,以便我可以测试一些服务器端方法.对于每个受保护的请求,我使用以下方法验证Firebase令牌:
firebase.auth().verifyIdToken(firebaseAccessToken).then(function(decodedToken) {
// forward request
})
Run Code Online (Sandbox Code Playgroud)
因此,在我的测试中,我使用Firebase数据库中的uid创建了一个令牌
firebase.auth().createCustomToken(uid).then(function(token) {
//add to header for requests
})
Run Code Online (Sandbox Code Playgroud)
后来我读到自定义标记未经verifyIdToken方法验证,只有客户端生成的标记验证.
我看过这个答案 - 服务器端验证firebase中的令牌
所以我将databaseAuthVariableOverride添加到init json中
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: [dbURL],
databaseAuthVariableOverride: {
uid: [uid]
}
});
Run Code Online (Sandbox Code Playgroud)
在我的测试中仍然得到输出
Error: expected 200 "OK", got 401 "Unauthorized"
Run Code Online (Sandbox Code Playgroud)
并且火力山错误 -
Error: Decoding Firebase ID token failed. Make sure you passed the entire string JWT which represents an ID token. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.
Run Code Online (Sandbox Code Playgroud)
那么如何使用我当前的设置模拟用户?
我在angularjs中使用嵌套指令时遇到了一些麻烦.我想从另一个指令中的指令调用一个控制器方法,并试图将参数传递给它,但它们是未定义的.
我试图用下面的selected.html中的三个参数调用remove().它在我引入父指令之前工作(televisionFilter.js)任何人都可以建议如何将这些指令传递给控制器?
谢谢!
码:
controller.js
$scope.remove = function(selectorToRemove, choicesArr, selectedArr){
console.log(selectorToRemove); //undefined
console.log(choicesArr); //undefined
console.log(selectedArr); //undefined
};
Run Code Online (Sandbox Code Playgroud)
televisionFilter.js
angular.module('app.directives').directive('televisionFilter', function(){
return{
restrict: 'A',
templateUrl: 'js/templates/television-filter.html',
scope: {
search: '=',
selectedBrand: '=',
submit: '&',
remove: '&'
}
};
});
Run Code Online (Sandbox Code Playgroud)
selected.js
angular.module('app.directives').directive('selected', function(){
return{
restrict: 'A',
templateUrl: 'js/templates/selected.html',
scope:{
choicesArr: '=',
selectedArr: '=',
remove: '&'
}
};
});
Run Code Online (Sandbox Code Playgroud)
list.html
<div television-filter search='televisionSearch' submit="submit()" selected-brand='selectedBrand' remove='remove(selectorToRemove, choicesArr, selectedArr)'></div>
Run Code Online (Sandbox Code Playgroud)
电视filter.html
<div selected selected-arr='search.selectedBrands' choices-arr='search.brands' remove='remove(selectorToRemove, choicesArr, selectedArr)'>
Run Code Online (Sandbox Code Playgroud)
selected.html
<ul>
<li ng-repeat="selected in selectedArr" class="filter-autocomplete-list" …Run Code Online (Sandbox Code Playgroud) javascript angularjs angularjs-directive angularjs-scope angularjs-controller
我想在突出显示/选择时对自定义表格视图单元格应用一些样式更改,以便覆盖isHighlighted并isSelected实现这一点。它适用于我的自定义集合视图单元格,但不适用于我点击自定义表格视图单元格。
我为表格视图和集合视图设置了完全相同的场景,并在自定义单元格上实现了以下内容:
override var isHighlighted: Bool {
didSet {
//called when I tap for CustomCollectionViewCell not for CustomTableViewCell
}
}
override var isSelected: Bool {
didSet {
//called when I tap for CustomCollectionViewCell not for CustomTableViewCell
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?为什么在点击表视图单元格时没有调用它?无论自定义单元格的内容如何,我尝试使用的任何表格视图都会发生这种情况。
我正在使用SwiftUI对列表中的展开和折叠进行动画处理。
如何获得截面的高度扩展以像在UIKit中使用tableview一样平滑地进行动画处理?
struct Rows: View {
let rows = ["Row 1", "Row 2", "Row 3", "Row 4", "Row 5"]
var body: some View {
Section {
ForEach(rows.identified(by: \.self)) { name in
Text(name)
.lineLimit(nil)
}
}
}
}
struct Header: View {
@State var isExpanded: Bool = false
var body: some View {
VStack(alignment: .leading) {
Button(action: {
self.isExpanded.toggle()
}) {
Text(self.isExpanded ? "Collapse Me" : "Expand Me")
.font(.footnote)
}
if self.isExpanded {
Rows().animation(.fluidSpring())
}
}
}
}
struct ContentView : …Run Code Online (Sandbox Code Playgroud) 我正在使用RMStore库- 这就是我目前所拥有的.
1)购买自动续订订阅并验证退回的收据.
[[RMStore defaultStore]addPayment:[Environment environment].premiumProductIAPId success:^(SKPaymentTransaction *transaction) {
[[RMStore defaultStore].receiptVerificator verifyTransaction:transaction success:^{
//enable premium service
} failure:^(NSError *error) {
}];
} failure:^(SKPaymentTransaction *transaction, NSError *error) {
}];
Run Code Online (Sandbox Code Playgroud)
2)在每次应用程序启动时,检查订阅是否为该日期的活动,如果是,则启用高级服务
RMAppReceipt *appReceipt = [RMAppReceipt bundleReceipt];
if (appReceipt){
NSInteger isActive = [appReceipt containsActiveAutoRenewableSubscriptionOfProductIdentifier:[Environment environment].premiumProductIAPId forDate:[NSDate date]];
//enable premium service if active
}
Run Code Online (Sandbox Code Playgroud)
3)如果用户在另一台设备上启动应用程序,则允许他们通过刷新收据来恢复购买(如果存在,并检查购买中是否存在有效订阅).
"In most cases, all your app needs to do is refresh its receipt and deliver the products in its receipt."
Run Code Online (Sandbox Code Playgroud)
- 那是来自指南.这是代码:
[[RMStore defaultStore]refreshReceiptOnSuccess:^{
if ([receipt containsActiveAutoRenewableSubscriptionOfProductIdentifier:[Environment …Run Code Online (Sandbox Code Playgroud) 一般来说,我知道在使用UIView.animate()时我们不需要自我弱,因为块没有强烈保持但是由于延迟,是否存在在下面的代码中使用弱的参数?为什么会有人说可能会有?
UIView.animate(withDuration: 0.1, animations: {
self.performAction()
}
Run Code Online (Sandbox Code Playgroud)
在下面的例子中我们为什么需要使用弱自/不需要使用弱自我...?
collectionView.performBatchUpdates({
self.collectionView.reloadData()
...
})
Run Code Online (Sandbox Code Playgroud) 我决心完全理解为什么这不会导致引用循环。一般来说,内存管理的每个阶段都发生了什么。
我有以下设置:
struct PresenterView: View {
@State private var isPresented = false
var body: some View {
Text("Show")
.sheet(isPresented: $isPresented) {
DataList()
}
.onTapGesture {
isPresented = true
}
}
}
struct DataList: View {
@StateObject private var viewModel = DataListViewModel()
var body: some View {
NavigationView {
List(viewModel.itemViewModels, id: \.self) { itemViewModel in
Text(itemViewModel.displayText)
}.onAppear {
viewModel.fetchData()
}.navigationBarTitle("Items")
}
}
}
class DataListViewModel: ObservableObject {
private let webService = WebService()
@Published var itemViewModels = [ItemViewModel]()
private var cancellable: AnyCancellable? …Run Code Online (Sandbox Code Playgroud) ios ×3
node.js ×3
javascript ×2
mocha.js ×2
swift ×2
swiftui ×2
angularjs ×1
chai ×1
combine ×1
date ×1
express ×1
firebase ×1
mongodb ×1
proxyquire ×1
retain-cycle ×1
rmstore ×1
sinon ×1
uitableview ×1
weak ×1