Related
How to set a header title in same row using const writeXlsxFile = require("write-excel-file/node");
HEADER_ROW = [
{
type: String,
value: 'John Smith',
span: 1,
sort: 1
},
{
type: String,
value: 'John Smith',
span: 3,
sort: 2
},
{
type: String,
value: 'John Smith',
span: 6,
sort: 4
}
]
This is how the Apollo query is defined:
const createUser = gql`
mutation(
$username: String!,
$email: String!,
$password: String!,
$time_created: String!,
$time_played: Int!,
$verified: Boolean!,
$type_user: Boolean!,
$userLevel: UserLevelInput!,
$ranks: RanksInput!,
$pvp: PvpInput!
){
createUser(
username: $username,
email: $email,
password: $password,
time_created: $time_created,
time_played: $time_played,
verified: $verified,
type_user: $type_user,
userLevel: $userLevel,
ranks: $ranks,
pvp: $pvp
){
username
email
password
}
}
`;
My schema:
const userSchema = new Schema({
username: String,
email: String,
password: String,
time_created: Date,
time_played: Number,
verified: Boolean,
type_user: Boolean,
userLevel: {
lidUnlocked: Number,
gidUnlocked: Number,
},
ranks: {
level: [
{
level: Number,
avgTime: Number,
rank: Number,
group: [
{
group: Number,
time: Number,
rank: Number,
},
],
},
],
},
pvp: {
points: Number,
rank: Number,
},
});
How I'm making the request:
const handleSubmit = (e) => {
e.preventDefault();
addUser({
variables: {
username: input.username,
email: input.email,
password: input.password,
time_created: Date.now(),
time_played: 0,
verified: false,
type_user: false,
userLevel: {
lidUnlocked: 1,
gidUnlocked: 1
},
ranks: {
level: [{
level: 1,
avgTime: 0,
rank: 0,
group: [{
group: 1,
time: 0,
rank: 0
}]
}]
},
pvp: {
points: 0,
rank: 0,
}
}
})
}
UserLevelInput, RanksInput and PvpInput:
const UserLevelInputType = new GraphQLInputObjectType({
name: "UserLevelInput",
fields: () => ({
lidUnlocked: { type: GraphQLInt },
gidUnlocked: { type: GraphQLInt },
}),
});
const RanksInputType = new GraphQLInputObjectType({
name: "RanksInput",
fields: () => ({
level: { type: new GraphQLList(LevelInputType) },
}),
});
const LevelInputType = new GraphQLInputObjectType({
name: "LevelInput",
fields: () => ({
level: { type: GraphQLInt },
avgTime: { type: GraphQLInt },
rank: { type: GraphQLInt },
group: { type: new GraphQLList(GroupInputType) },
}),
});
const GroupInputType = new GraphQLInputObjectType({
name: "GroupInput",
fields: () => ({
group: { type: GraphQLInt },
time: { type: GraphQLInt },
rank: { type: GraphQLInt },
}),
});
const PvpInputType = new GraphQLInputObjectType({
name: "PvpInput",
fields: () => ({
points: { type: GraphQLInt },
rank: { type: GraphQLInt },
}),
});
If i make this mutation on localhost:5005/graphql it works as intended:
mutation{
createUser(
username:"babadany2999",
email:"babadany2999#gmail.com",
password:"Immboold1",
time_created:"1645738406658",
time_played: 0,
verified: false,
type_user: false,
userLevel:{
lidUnlocked: 1,
gidUnlocked: 1
},
ranks: {
level: [{
level: 1,
avgTime: 0,
rank: 0,
group:[{
group: 1,
time: 0,
rank: 0
}]
}]
},
pvp: {
points: 0,
rank: 0
}
), {
username
email
password
}
}
Also if I make the request(with the code not in /graphql) and then check out Apollo Dev tools for that particular mutation, I get that the Int, UserLevelInput, RanksInput and PpvInput types are not known.
Apollo Dev Tools type unknown
For anyone encountering the same problem, I managed to "fix" it by creating constants of the complex objects and simply setting the default to those constants in the mongoose table and not giving that as input to apollo.
username: String,
email: String,
password: String,
time_created: {
type: Date,
default: new Date()
},
time_played: {
type: Number,
default: 0
},
type_user: {
type: Boolean,
default: false
},
verified: {
type: Boolean,
default: false
},
userLevel: {
lidUnlocked: Number,
gidUnlocked: Number
},
ranks: {
type: Object,
default: ranks
},
pvp: {
points: {
type: Number,
default: 0
},
rank: Number
}
})
And part of the constant(it's very long but it has the same structure until the end):
const ranks= {
level: [
{
level: 1,
group: [
{ group: 1, unlocked: true, time: 0, rank: 0 },
{ group: 2, unlocked: false, time: 0, rank: 0 },
{ group: 3, unlocked: false, time: 0, rank: 0 },
{ group: 4, unlocked: false, time: 0, rank: 0 },
{ group: 5, unlocked: false, time: 0, rank: 0 },
{ group: 6, unlocked: false, time: 0, rank: 0 },
{ group: 7, unlocked: false, time: 0, rank: 0 },
{ group: 8, unlocked: false, time: 0, rank: 0 },
{ group: 9, unlocked: false, time: 0, rank: 0 },
{ group: 10, unlocked: false, time: 0, rank: 0 },
{ group: 11, unlocked: false, time: 0, rank: 0 },
{ group: 12, unlocked: false, time: 0, rank: 0 },
{ group: 13, unlocked: false, time: 0, rank: 0 },
],
unlocked: true,
avgTime: 0,
rank: 0,
},
I'm having a problem into convert json into a string array
I need transform a json into a string array because I will do a INSERT into our database dynamically, because this need work for any json and I don't know how is the JSON that I will receive.
This is my response
[
{
consumer: 'consumer a',
orders: [{
orderNumber: 1,
details: {
dates: { deadline: '2022-02-17' },
status: [{ id: 1, status: 'Pending', date: '2022-01-01' },
{ id: 2, status: 'Awaiting Payment', date: '2022-01-02' },
{ id: 3, status: 'Awaiting Fulfillment', date: '2022-01-02' }]
}
},
{
orderNumber: 2,
details: {
dates: { deadline: '2022-03-17' },
status: [{ id: 1, status: 'Pending', date: '2022-01-01' }]
}
}]
},
{
consumer: 'consumer b',
orders: [{
orderNumber: 6,
details: {
dates: { deadline: '2022-02-17' },
status: [{ id: 1, status: 'Pending', date: '2022-01-01' }]
}
},
{
orderNumber: 7,
details: {
dates: { deadline: '2022-03-17' },
status: [{ id: 1, status: 'Pending', date: '2022-03-01' },
{ id: 2, status: 'Awaiting Payment', date: '2022-04-02' },
{ id: 3, status: 'Awaiting Fulfillment', date: '2022-05-02' }]
}
}]
}
]
I need this result
['consumer a', '1', '1'],
['consumer a', '1', '2'],
['consumer a', '1', '3'],
['consumer a', '2', '1'],
['consumer b', '6', '1'],
['consumer b', '7', '1'],
['consumer b', '7', '2'],
['consumer b', '7', '3']
I created a map for reach this objective
like this
['consumer', 'consumer.orders.orderNumber', 'consumer.orders.detaisl.status.id']
But can't do that, someone have any idea?
You can use a reduce function then traverse each order and again for each status, then return the accumulator
const arr = [
{
consumer: 'consumer a',
orders: [{
orderNumber: 1,
details: {
dates: { deadline: '2022-02-17' },
status: [{ id: 1, status: 'Pending', date: '2022-01-01' },
{ id: 2, status: 'Awaiting Payment', date: '2022-01-02' },
{ id: 3, status: 'Awaiting Fulfillment', date: '2022-01-02' }]
}
},
{
orderNumber: 2,
details: {
dates: { deadline: '2022-03-17' },
status: [{ id: 1, status: 'Pending', date: '2022-01-01' }]
}
}]
},
{
consumer: 'consumer b',
orders: [{
orderNumber: 6,
details: {
dates: { deadline: '2022-02-17' },
status: [{ id: 1, status: 'Pending', date: '2022-01-01' }]
}
},
{
orderNumber: 7,
details: {
dates: { deadline: '2022-03-17' },
status: [{ id: 1, status: 'Pending', date: '2022-03-01' },
{ id: 2, status: 'Awaiting Payment', date: '2022-04-02' },
{ id: 3, status: 'Awaiting Fulfillment', date: '2022-05-02' }]
}
}]
}
]
const result = arr.reduce((acc,val)=>{
val.orders.forEach(o=>o.details.status.forEach(s=>acc.push([val.consumer, o.orderNumber.toString(), s.id.toString()])))
return acc
},[])
console.log(result)
[ { id: 4,
category_id: 7,
user_id: 2,
title: '',
image1: '15717679702861gohz24vrk2262fov.jpg',
image2: '15717679702891gohz24vrk2262fox.jpg',
image3: '15717679702911gohz24vrk2262foz.jpg',
image4: '15717679702921gohz24vrk2262fp0.jpg',
image5: '15717679702931gohz24vrk2262fp1.jpg',
status: 2,
created_at: 2019-10-22T18:12:50.000Z,
updated_at: 2019-10-22T18:12:50.000Z,
item_id: 1,
category_field_id: 4,
value: 'Iphone',
is_title: 1,
is_description: 0 },
{ id: 3,
category_id: 7,
user_id: 2,
title: '',
image1: '15717679702861gohz24vrk2262fov.jpg',
image2: '15717679702891gohz24vrk2262fox.jpg',
image3: '15717679702911gohz24vrk2262foz.jpg',
image4: '15717679702921gohz24vrk2262fp0.jpg',
image5: '15717679702931gohz24vrk2262fp1.jpg',
status: 2,
created_at: 2019-10-22T18:12:50.000Z,
updated_at: 2019-10-22T18:12:50.000Z,
item_id: 1,
category_field_id: 3,
value: 'Other',
is_title: 0,
is_description: 0 },
{ id: 11,
category_id: 7,
user_id: 2,
title: '',
image1: '15718960965161gohz24rzk24acmit.jpg',
image2: '15718960965181gohz24rzk24acmiu.jpg',
image3: '15718960965191gohz24rzk24acmiv.jpg',
image4: '15718960965201gohz24rzk24acmiw.jpg',
image5: '15718960965221gohz24rzk24acmiy.jpg',
status: 0,
created_at: 2019-10-24T05:48:16.000Z,
updated_at: 2019-10-24T05:48:16.000Z,
item_id: 3,
category_field_id: 3,
value: 'Other',
is_title: 0,
is_description: 0 } ]
i want to group by this on item_id. but only those who have a specific length that is enter by user (number of inputs by user in search)
suppose length is 2 so the item that having only two object included in final result;
like
{
1: [{ id: 4,
category_id: 7,
user_id: 2,
title: '',
image1: '15717679702861gohz24vrk2262fov.jpg',
image2: '15717679702891gohz24vrk2262fox.jpg',
image3: '15717679702911gohz24vrk2262foz.jpg',
image4: '15717679702921gohz24vrk2262fp0.jpg',
image5: '15717679702931gohz24vrk2262fp1.jpg',
status: 2,
created_at: 2019-10-22T18:12:50.000Z,
updated_at: 2019-10-22T18:12:50.000Z,
item_id: 1,
category_field_id: 4,
value: 'Iphone',
is_title: 1,
is_description: 0 },
{ id: 3,
category_id: 7,
user_id: 2,
title: '',
image1: '15717679702861gohz24vrk2262fov.jpg',
image2: '15717679702891gohz24vrk2262fox.jpg',
image3: '15717679702911gohz24vrk2262foz.jpg',
image4: '15717679702921gohz24vrk2262fp0.jpg',
image5: '15717679702931gohz24vrk2262fp1.jpg',
status: 2,
created_at: 2019-10-22T18:12:50.000Z,
updated_at: 2019-10-22T18:12:50.000Z,
item_id: 1,
category_field_id: 3,
value: 'Other',
is_title: 0,
is_description: 0 }
]
}
By default, lodash doesn't provide the feature you need.
Instead, you can try combining _groupBy and _pickBy functions.
var groupedItems = _.groupBy(items, 'item_id');
var userSearchLength = 2;
var filteredGrouping = _.pickBy(groupedItems, function(value, key) {
return value.length == userSearchLength;
});
const userInputNumber = 2;
let grouped =_groupBy(obj,(o)=> o.item_id)
Object.keys(grouped).forEach(item_id=> {
if(grouped[item_id].length !== userInputNumber){
delete grouped[item_id];
}
})
You'll have to group first and then check and delete groups which don't have the length of array you desire.
I hope this will help you.
You can first group the data and then filter the data that you needed.
const givenLength = 2;
const groupData =_.groupBy(data,(o)=> o.item_id);
const filtered = _.filter(groupData, (o) => o.length === givenLength );
I have created a form using ExtJs 4
xtype: 'prg-formPanel',
id: 'blog-edit-form', // id fixed : id: 'upload-form-'+this.filetype,
url: baseUrl + "crud",
border: 0,
bodyStyle: {
padding: '10px 20px'
},
height: 600,
defaultType: 'textfield',
defaults: {
anchor: '95%',
allowBlank: true,
msgTarget: 'side',
labelWidth: 60
},
layout: {
type: 'table',
columns: 2
},
items: [{
inputType: 'hidden',
id: 'actionType',
name: 'actionType',
value: this.actionType,
scope: this
},{
inputType: 'hidden',
id: 'id',
name: 'id',
value: (Ext.isEmpty(this.record)?null:this.record.get('id'))
},{
inputType: 'textfield',
id: 'title',
fieldLabel: 'Başlık',
name: 'title',
labelWidth: 60,
value: (Ext.isEmpty(this.record)?null:this.record.get('title')),
colspan:2
},{
inputType: 'textfield',
id: 'name',
fieldLabel: 'İsim',
name: 'name',
labelWidth: 60,
value: (Ext.isEmpty(this.record)?null:this.record.get('name')),
colspan:2
},
new Prg.checkBox({
fieldLabel: 'Aktif mi?',
name: 'activeFlag',
labelWidth: 60,
checked: (Ext.isEmpty(this.record)?false:this.record.get('activeFlag'))
}),
new Prg.idCombo({
fieldLabel : 'Dil',
labelWidth: 60,
emptyText : 'Dili seçiniz...',
id: 'langId',
name : 'langId',
store : this.ds_language,
scope: this
}),{
inputType: 'textfield',
id: 'targetURL',
fieldLabel: 'Link',
name: 'targetURL',
labelWidth: 60,
value: (Ext.isEmpty(this.record)?null:this.record.get('targetURL')),
colspan:2
},{
xtype: "TinyMCEEditor",
fieldLabel: "İçerik",
width: 800,
height: 400,
colspan:2,
name: "contentHTML",
id: "contentHTML",
tinyMCESettings: {
mode: "exact",
theme: "advanced",
skin: "o2k7",
// Tiny Settings Here
//...
value: (Ext.isEmpty(this.record)?"":this.record.get('contentHTML'))
},
new Ext.form.field.ComboBox({
id: "categories",
name: "categories",
fieldLabel: 'Kategori',
multiSelect: true,
displayField: 'name',
forceSelection: true,
labelWidth: 60,
store: this.ds_tags,
queryMode: 'remote',
scope: this,
colspan:2
})
] // Form items closure
}];
this.buttons = [new Prg.btn({
text: btnUploadMsg,
handler: this.onSave,
scope: this
}),new Prg.btn({
text: btnCancelMsg,
handler: function() {
this.hide();
},
scope: this
})];
this.callParent(arguments);
this.form = this.getComponent('blog-edit-form').getForm(); // 'upload-form-'+this.filetype
}
as you see, I used table layout, some form items should be inline, others shoul be in the new line. I have done it by table, however, now items width is fixed...
I am also want to give them 95% value to get them resize automatically when window resize. I cant find the way. try to add anchor and width: '90%' but it does not work.
Use the default layout for forms: form and use FieldContainer http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.FieldContainer where you need to show two fields on the same row.
This way you can leverage anchor and still create a complex layout like the one you want.
This should work (i cannot test it because of custom types)
Ext.define('Prg.FormPanel', {
initComponent: function() {
Ext.applyIf(this, {
xtype: 'prg-formPanel',
id: 'blog-edit-form',
// id fixed : id: 'upload-form-'+this.filetype,
url: baseUrl + "crud",
border: 0,
bodyStyle: {
padding: '10px 20px'
},
height: 600,
defaultType: 'textfield',
defaults: {
anchor: '95%',
allowBlank: true,
msgTarget: 'side',
labelWidth: 60
},
layout: {
type: 'form'
},
items: [{
inputType: 'hidden',
id: 'actionType',
name: 'actionType',
value: this.actionType,
scope: this
}, {
inputType: 'hidden',
id: 'id',
name: 'id',
value: (Ext.isEmpty(this.record) ? null : this.record.get('id'))
}, {
inputType: 'textfield',
id: 'title',
fieldLabel: 'Başlık',
name: 'title',
labelWidth: 60,
value: (Ext.isEmpty(this.record) ? null : this.record.get('title'))
}, {
inputType: 'textfield',
id: 'name',
fieldLabel: 'İsim',
name: 'name',
labelWidth: 60,
value: (Ext.isEmpty(this.record) ? null : this.record.get('name'))
}, {
xtype: 'fieldcontainer',
layout: 'hbox',
items: [
new Prg.checkBox({
fieldLabel: 'Aktif mi?',
name: 'activeFlag',
labelWidth: 60,
checked: (Ext.isEmpty(this.record) ? false : this.record.get('activeFlag'))
}), new Prg.idCombo({
fieldLabel: 'Dil',
labelWidth: 60,
emptyText: 'Dili seçiniz...',
id: 'langId',
name: 'langId',
store: this.ds_language,
scope: this
})]
}, {
inputType: 'textfield',
id: 'targetURL',
fieldLabel: 'Link',
name: 'targetURL',
labelWidth: 60,
value: (Ext.isEmpty(this.record) ? null : this.record.get('targetURL'))
}, {
xtype: "TinyMCEEditor",
fieldLabel: "İçerik",
width: 800,
height: 400
name: "contentHTML",
id: "contentHTML",
tinyMCESettings: {
mode: "exact",
theme: "advanced",
skin: "o2k7",
// Tiny Settings Here
//...
value: (Ext.isEmpty(this.record) ? "" : this.record.get('contentHTML'))
},
new Ext.form.field.ComboBox({
id: "categories",
name: "categories",
fieldLabel: 'Kategori',
multiSelect: true,
displayField: 'name',
forceSelection: true,
labelWidth: 60,
store: this.ds_tags,
queryMode: 'remote',
scope: this
})] // Form items closure
});
this.buttons = [new Prg.btn({
text: btnUploadMsg,
handler: this.onSave,
scope: this
}), new Prg.btn({
text: btnCancelMsg,
handler: function() {
this.hide();
},
scope: this
})];
this.callParent(arguments);
this.form = this.getComponent('blog-edit-form').getForm(); // 'upload-form-'+this.filetype
}
});
Hope this helps.
Maybe you can use a Resizer?
Here are some examples.