I have been working on a node.js odata server based on this example: How to set up a nodejs OData endpoint with odata-server
I have everything working... I can read, update, insert, delete. But I am trying to associate a Journal with a Tasks and I am having problems.
I have tried several different ways outlined here: Operations (OData Version 2.0)
Here is my code:
/* global $data */
require('odata-server');
$data.Class.define("Task", $data.Entity, null, {
Id: { type: "id", key: true, computed: true, nullable: false },
Title: { type: "string", required: true, maxLength: 200 },
Journals: { type: "array", elementType: "Journal"
, inverseProperty: "Task" }
});
$data.Class.define("Journal", $data.Entity, null, {
Id: { type: "id", key: true, computed: true, nullable: false },
Entry: { type: "string" },
DateInserted: { type: "string" },
Task: { type: "object", elementType: "Task" , inverseProperty: "Journals" }
});
$data.EntityContext.extend("obb", {
Tasks: { type: $data.EntitySet, elementType: Task },
Journals: { type: $data.EntitySet, elementType: Journal }
});
$data.createODataServer(obb, '/api-v0.1', 2046, 'localhost');
Question:
Is this feature even available from odata-server what would the post look like to link a Journal to a Task?
I am using fiddler2 and composing a POST I have tried these urls:
//localhost:2046/api-v0.1/Tasks('the-id-of-a-task')/Journals
//localhost:2046/api-v0.1/Tasks('the-id-of-a-task')/Journals/$link
post body's I have tried:
{"Entry":"This is a test"}
{"url":"http://localhost:2046/api-v0.1/Journals('id-of-a-journal-in-the-db')"}
I have even tried to build out and post a Task with journals together and that didn't work.
Any help would be greatly appreciated. Thanks.
Related
Forgive my limited knowledge im about a week into using Sequelize,
Models.PlannerModel.Builds.findAll({
raw: true,
where: {
ProposedDelivery: { [Op.gt]: moment().format("YYYY-MM-DD") },
description: { [Op.ne]: null },
description: { [Op.ne]: " " },
description: { [Op.not]: null },
},
include: [
{
model: Models.PlannerModel.Unit,
required: true
},
],
the result from the above is as you would expect except all the keys for the fields in the includes are as strings so referencing them in my Pug template/class has to be done with brackets
overall not the end of the world just wondering if im doing something wrong ?
Cheers!
Turn off raw to get nested model objects and also to get plain objects use get({ plain: true}) for each returned model instance:
const builds = await Models.PlannerModel.Builds.findAll({
where: {
ProposedDelivery: { [Op.gt]: moment().format("YYYY-MM-DD") },
[Op.and]: [{
description: { [Op.ne]: null },
}, {
description: { [Op.ne]: " " },
}, {
description: { [Op.not]: null },
}
]
},
include: [
{
model: Models.PlannerModel.Unit,
required: true
},
]
})
const plainBuilds = builds.map(x => x.get({ plain: true }))
Please pay attention that I changed conditions with description. In your version of conditions only the last one will work because JS saves only the last key if there are several same keys in the same object.
It's simple: I want to be able to support directly adding content to the TF script, or refer to a file with that data, but not both. When I try this, I get an error
content: ConflictsWith cannot be set with Required
Schema: map[string]*schema.Schema{
"content": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
ConflictsWith: []string{"file"},
},
"file": {
Type: schema.TypeString,
Sensitive: true,
Required: true,
ConflictsWith: []string{"content"},
},
}
How can I make this terraform provider either accept a file, OR content, but not both? Obviously, if I set both to optional then neither is required.
Actually, this was easier than I thought. Looking at the schema.Schema struct produced an answer:
ExactlyOneOf
schema.Resource{
Schema: map[string]*schema.Schema{
"alias": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"content": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
},
"file": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
ExactlyOneOf: []string{"content", "file"},
},
}
}
Which, when tested, produces this error: - "file": only one of content,filecan be specified, butcontent,file were specified.
We can thus use the ExpectError and match this
func TestHasFileAndContentFails(t *testing.T){
const conflictsResource = `
resource "artifactory_certificate" "fail" {
alias = "fail"
file = "/this/doesnt/exist.pem"
content = "PEM DATA"
}
`
resource.Test(t, resource.TestCase{
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: conflictsResource,
ExpectError: regexp.MustCompile(`.*only one of .* can be specified, but .* were specified.*`),
},
},
})
}
It's brittle in that a debug string now has meaning, and I would expect the validation to be on the entire schema as a final phase. But, this works
I have two models: platform and place (platform and place on platform)
platform
{
name: {
required: true,
unique: true,
type: String,
empty: false
},
description: {
required: false,
type: String,
empty: true
}
}
place
{
name: {
required: true,
type: String,
empty: false
},
platform: new Mongoose.Schema({
type: Mongoose.Schema.Types.ObjectId,
ref: PlatformSchema
})
}
The name of platform must be unique. First, I generate list of platforms. Then trying generate list of places on this platforms and receive error.
WriteError({
"code": 11000,
"index": 1,
"errmsg": "E11000 duplicate key error collection: test.places index: platform.ref.name_1 dup key: { : null }",
"op": {
"_id": "5b7ea477798f9c41f81c0234",
"name": "top",
"platform": {
"_id":"5b7ea41b878b4a41abcfc952"
}
}
})
Receive it until unique index for "name" field exists in platform schema.
I try insert place many ways:
PlaceRecord.insertMany([
{
name: "top",
platform: platformDocumentInstance
}
])
or
PlaceRecord.insertMany([
{
name: "top",
platform: platformDocumentInstance
}
])
or
PlaceRecord.insertMany([
{
name: "top",
platform: platformDocumentInstance
}
])
But result is same one. Note first record of place success inserted, but next record of place throw the exception. Please help.
It seems the document that you are inserting first has inserts null as platform.ref.name and when you insert second document your index platform.ref.name_1 fails because there is already a record with null.
i use Express-js and express graphQL module to create my endpoint and web service ;
i am looking for way to create custom response in graphQL my endpoint is simple
select books from database my response is
{
"data": {
"books": [
{
"id": "5b5c02beab8dc1182b2e0a03",
"name": "dasta"
},
{
"id": "5b5c02c0ab8dc1182b2e0a04",
"name": "dasta"
}
]
}
}
but in need something like this
{
"result": "success",
"msg" : "list ...",
"data": [
{
"id": "5b5c02beab8dc1182b2e0a03",
"name": "dasta"
},
{
"id": "5b5c02c0ab8dc1182b2e0a04",
"name": "dasta"
}
]
}
here is my bookType
const BookType = new GraphQLObjectType({
name: 'Book',
fields: () => ({
id: {type: GraphQLID},
name: {type: GraphQLString},
genre: {type: GraphQLString},
author_id: {type: GraphQLString},
author: {
type: AuthorType,
resolve(parent, args) {
return Author.findById(parent.author_id);
}
}
})
});
That's not a legal GraphQL response. As per section 7.1 of the spec, after describing the data, errors, and extensions: top-level keys:
... the top level response map must not contain any entries other than the three described above.
You might put this data into extensions; or make it an explicit part of your GraphQL API; or simply let "success" be implied by the presence of a result and the lack of an error.
I have my extjs application. As of now i am getting all my records from backend, full record set in 1 service request. I need to implement the pagination and sorting at UI level. Sorting seems be simple. How do i implement UI level pagination? Any example for this? I am getting 10-20k records so it is fine if i implement pagination at UI level? Can extjs6 handle the load?
I'd recommend you handle paging server-side. Right now you might only have 10-20k records, but what if it grows to 100k? or 1 million?
Take a look at this guide from Sencha: Grids - Paging. It explains a lot.
Good luck!
Sorting is implemented out of box. This is simple pagination example based on default ExtJs 6.2.0 application.
YourAppName.view.main.List
...
// bottom paging-bar definition. Use "tbar" for top bar, or define both.
bbar: {
xtype: 'pagingtoolbar',
displayInfo: true,
emptyMsg: 'No data to display',
items: ['->'],
prependButtons: true
}
...
items: [{
title: 'Home',
iconCls: 'fa-home',
layout: 'fit', // needed for scrolling
scrollable: true, // for scrollable items
items: [{
xtype: 'mainlist'
}]
}, {
...
YourAppName.store.Personnel
Ext.define('YourAppName.store.Personnel', {
extend: 'Ext.data.Store',
alias: 'store.banners',
autoLoad: true, // run ajax-query right after grid rendering
loadMask: true, // show preload image
pageSize: 100,
model: 'YourAppName.model.Person',
proxy: {
type: 'ajax',
url: '/personnel',
reader: {
type: 'json',
rootProperty: 'items',
totalProperty: 'total'
}
}
});
Create in app/model folder file Person.js with:
YourAppName.model.Person
Ext.define('YourAppName.model.Person', {
extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string', defaultValue: '' },
{ name: 'email', type: 'string', defaultValue: '' },
{ name: 'phone', type: 'string', defaultValue: '' }
]
});
As of store definition your web-server must be able to response on HTTP GET-request on URI /personnel with json like this:
{
"success": true,
"total": 20000,
"items": [
{ "name": "Jean Luc", "email": "jeanluc.picard#enterprise.com", "phone": "555-111-1111" },
{ "name": "Worf", "email": "worf.moghsson#enterprise.com", "phone": "555-222-2222" },
{ "name": "Deanna", "email": "deanna.troi#enterprise.com", "phone": "555-333-3333" },
{ "name": 'Data', "email": "mr.data#enterprise.com", "phone": "555-444-4444" }
...
]
}