what would be the correct type for "tools" in EnterpriseInput input? - api

input EnterpriseInput {
cnpj: String
name: String
email: String
password: String
tools: Tool
}
type Enterprise {
id: ID!
cnpj: String!
name: String!
email: String!
password: String!
tools: [Tool]
}
type Tool {
id: ID!
name: String!
brand: String!
cod: String!
qnt: Int!
}
type Query {
enterprises: [Enterprise]
enterprise( id: ID!): Enterprise
}
type Mutation {
createEnterprise( input: EnterpriseInput!): Enterprise!
# updateEnterprise( id: ID!, input: EnterpriseInput!): Enterprise!
deleteEnterprise( id: ID!): Boolean,
}
Error message on console:
C:\Users\Elias\code\web\backEnd-gestordeferramentas\node_modules\graphql\type\validate.js:69
throw new Error(errors.map(function (error) {
^
Error: The type of EnterpriseInput.tools must be Input Type but got: Tool.
at assertValidSchema (C:\Users\Elias\code\web\backEnd-…

In a mutation you cannot use standard Object type and must use Input type instead. And in input type you must use input type
So instead of
input EnterpriseInput {
cnpj: String
name: String
email: String
password: String
tools: Tool
}
Try this
input ToolInput {
id: ID!
name: String!
brand: String!
cod: String!
qnt: Int!
}
input EnterpriseInput {
cnpj: String
name: String
email: String
password: String
tools: ToolInput
}

Related

Data type for an array of Object in realm - react-native realm

I'm using realm for Javascript using React-native
I want to generate a realm schema to hold an array of Object as this:
arrayOfObj:[{ key1:1111, key2:2222, key3:333 }]
What I have tried so far is using the mixed type in my schema
const mySchema = {
name: "mySchema",
properties: {
_id: "objectId",
arrOfObj: "mixed" //'have used mixed[] too but they all don't work
}
}
I have tried using mixed and also using mixed[] but when I try to insert the array of object i get the error: mySchema.arrOfObj must be of type 'mixed?[]', got 'object' ([object Object])].
Now, What is the correct data type for the array of object in realm?
const myScheme = {
name: "myScheme",
primaryKey: "_id",
properties: {
_id: "objectId",
_partition: "string",
name: "string",
tasks: "myData[]"
}
};
const myData = {
name: "myData",
primaryKey: "_id",
properties: {
_id: "objectId",
_partition: "string",
firstname: "string",
lastname: "string",
}
};

Mongoose population issue at express.js

Hello evryone i have issue last 2 days tryin to populate reviews on company list.
Im trying to get list of all companys with their reviews.
Every review is assigned to company Id.
On postman response i get empty array : []
Here is the code im having isuses with;
Company Model:
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var slug = require("mongoose-slug-generator");
mongoose.plugin(slug);
var CompanySchema = new Schema({
title: {type: String, required: true},
slug: { type: String, slug: "title" },
address: {type: String, required: true},
totalRating: {type: Number, required: false},
description: {type: String, required: false},
facebookLink: {type: String, required: false},
twitterLink: {type: String, required: false},
googleLink: {type: String, required: false},
linkedIn:{type: String, required: false},
instagramLink:{type: String, required: false},
contactNumber:{type: Number, required: false},
website:{type: String, required: false},
email:{type: String, required: false},
review: [{type: Schema.Types.ObjectId, ref: "Review"}],
user: { type: Schema.ObjectId, ref: "User", required: true },
}, {timestamps: true});
module.exports = mongoose.model("Company", CompanySchema);
Review Model :
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var ReviewSchema = new Schema({
title: {type: String, required: true},
description: {type: String, required: true},
rating: {type: String, required: true},
user: { type: Schema.ObjectId, ref: "User", required: true },
company: {type: Schema.ObjectId, ref:"Company"}
}, {timestamps: true});
module.exports = mongoose.model("Review", ReviewSchema);
And where i populate it :
exports.companyList = [
function (req, res) {
try {
Company.
find({id: req._id}).
populate("review").
then((companies)=>{
if(companies.length > 0){
return apiResponse.successResponseWithData(res, "Uspješno 1", companies);
}else{
return apiResponse.successResponseWithData(res, "Uspješno 2", []);
}
});
} catch (err) {
//Baci error 500...
return apiResponse.ErrorResponse(res, err);
}
}
];
Ive tryed evrything thanks infront.
Try changing in your Company Model
review: [{type: Schema.Types.ObjectId, ref: "Review"}]
to
review: {type: Schema.Types.ObjectId, ref: "Review"}
Then when you try to populate, I assume you either pass the _id of the company in your params or body of the request, so most likely:
req.params.id
or
req.body.id
the actual function:
module.exports = {
fncName: (req, res) => {
Company.findById(req.params.id)
.populate({
path: 'review',
})
.exec((err, company) => {
if (!err) {
if(companies.length > 0){
return apiResponse.successResponseWithData(res, "Uspješno 1", companies);
}else{
return apiResponse.successResponseWithData(res, "Uspješno 2", []);
}
}else {
console.log(err)
}
})
}
}
I am not sure how you register the router but it could look something like this:
const router = require ('express-promise-router')();
router.get('/get-company', nameOfTheController.fncName);
Note: to populate review from Company Model you do not necessarily need this line in your Review Model:
company: {type: Schema.ObjectId, ref:"Company"}

Vue.js - using Vuelidate url domain should match email domain

I have two inputs field : url and email
I'm using Vuelidate and I want to make a custom validator where it checks if the url domain name is equal to the email domain name.
Valid example :
url: (https://)www.mydomain.example
email: johndoe#mydomain.example
Invalid example :
url: (https://)www.mydomain.example
email: johndoe#somedomaine.example
validations object :
validations: {
form: {
url: { required, url, maxLength: maxLength(2083) },
email: { required, email, maxLength: maxLength(255) },
lastName: { required, maxLength: maxLength(100) },
firstName: { required, maxLength: maxLength(100) }
}
},
You could use a custom validator called matchUrl as follow :
const matchUrl=(value, vm) =>
value.substring(value.indexOf("#")+1) ===vm.url.substring(vm.url.indexOf(".")+1);
And use it as :
validations: {
form: {
url: { required, url, maxLength: maxLength(2083) },
email: { required,matchUrl, email, maxLength: maxLength(255) },
lastName: { required, maxLength: maxLength(100) },
firstName: { required, maxLength: maxLength(100) }
}
},
check this working example

Creating mongoose schema that contains array of Objects

How do I create a mongoose schema that has the following structure
{
data: {
name: "John doe",
attributes: [
{
text: "Sample text",
created_at: "2018-08-23"
},
{
text: "Sample text 2",
created_at: "2018-08-23"
}
],
created_at: "2018-08-23"
}
}
This can simply be done with Arrays of Objects instead of creating New Schemas. I don't know if there might be some implications for the optimization.
attributes: [{
text: String,
created_at: Date
}],
This is following the official Mongoose documentation.
You can try this
const sampleSchema = new mongoose.Schema({
data: {
type: dataSchema
}
});
const dataSchema = new mongoose.Schema({
name: String,
attributes: [attributeSchema],
created_at: Date
});
const attributeSchema = new mongoose.Schema({
text: String,
created_at: Date
});

How to add id field to JsonObject using SORM in play framework on scala?

this is my case class:
case class Admin(name: String, surname: String, login: String, password: String
this is my json formatter:
implicit val adminWrite: Writes[Admin] = (
(JsPath \ "name").write[String] and
(JsPath \ "surname").write[String] and
(JsPath \ "login").write[String] and
(JsPath \ "password").write[String]
)(unlift(Admin.unapply))
what i get:
{
name: "ddd",
surname: "ddd",
login: "djamik123",
password: "djamik123"
}
what i need:
{
id: 1,
name: "ddd",
surname: "ddd",
login: "djamik123",
password: "djamik123"
}
Is there a way to solve this problem?