Skip to content

Instantly share code, notes, and snippets.

View shipcake's full-sized avatar

nattapong melont shipcake

View GitHub Profile
const { gql} = require('apollo-server-express')
const account = gql`
type token {
token:String,
date:String,
country:String,
city:String,
ip:String,
@shipcake
shipcake / [pid].js
Last active July 10, 2019 08:59
test dynamic route Error??
// products/[pid].js
import React from 'react'
const productID = (props) => {
return <>Test slug: {props.pid}</>
}
productID.getInitialProps = ({query}) => {
const {pid} =query
return {pid}
@shipcake
shipcake / show.js
Created July 13, 2019 11:39
.find mongoose array in document not work
const { products } = require('../../../../mongo/model') //import categories mongo model
const show_products = async(_,{offset,limit},ctx) => {
console.log('offset'+offset)
console.log('limit'+limit)
const res = await products.find({"storeuid":ctx.token.storeuid},null,{skip:offset,limit:limit})
console.log(res) //return all object in array
return res
}
module.exports={show_products}
@shipcake
shipcake / gist:c5e2221a25c9032f04c2931435aa0fcc
Created July 19, 2019 13:12
how to pull all object in array by data._id condition?
//find property_type in products to delete them.
const findallid = await products.findOne({ "storeuid": ctx.token.storeuid}).lean()
const MapId = await R.map(findallid.data,i=>{
return i._id
})
console.log(MapId) <--- return like [id1,id2...]
const remove = await products.findOneAndUpdate(
{ "storeuid": ctx.token.storeuid },
{
"name": "mfront",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"test": "echo \"Error: no test specified\" && exit 1"