Skip to content

Instantly share code, notes, and snippets.

View LanciWeb's full-sized avatar

Marco Lancellotti LanciWeb

View GitHub Profile
@LanciWeb
LanciWeb / App.js
Last active October 16, 2020 16:01
App.js final for the Fastify + React Admin project on Medium
import React from 'react';
import dataProvider from './dataProvider';
import { Admin, Resource } from 'react-admin';
import NotesList from './components/NotesList';
import NotesEdit from './components/NotesEdit';
import NotesCreate from './components/NotesCreate';
function App() {
return (
<Admin dataProvider={dataProvider}>
@LanciWeb
LanciWeb / App.js
Last active October 16, 2020 16:01
App.js with Admin for the Fastify + React Admin project on Medium
import React from 'react';
import { Admin} from 'react-admin';
import dataProvider from './dataProvider';
function App() {
return (
<Admin dataProvider={dataProvider} />
);
}
@LanciWeb
LanciWeb / dataProvider.js
Created October 16, 2020 14:04
dataPRovider for the Fastify + React Admin project on Medium
import { fetchUtils } from 'react-admin';
import { stringify } from 'query-string';
const apiUrl = 'http://localhost:3000/api';
const httpClient = fetchUtils.fetchJson;
export default {
getList: (resource, params) => {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
@LanciWeb
LanciWeb / App.js
Created October 16, 2020 13:27
Clean App js for the Fastify + React Admin project on Medium
import React from 'react';
function App() {
return <div className="App">Hello world</div>
}
export default App;
@LanciWeb
LanciWeb / Note.js
Created October 15, 2020 18:02
Note model for the Fastify + React Admin project on Medium
const mongoose = require('mongoose');
const { Schema } = mongoose;
const noteSchema = new Schema({
text: { type: String, required: true },
});
const Note = mongoose.model('note', noteSchema);
module.exports = Note;
@LanciWeb
LanciWeb / noteRoutes.js
Created October 15, 2020 18:00
V1 routes for the Fastify + React Admin project on Medium
module.exports = (app) => {
// create a note
app.post('/api/notes', (request, reply) => {});
// get the list of notes
app.get('/api/notes', (request, reply) => {});
// get a single note
app.get('/api/notes/:id', (request, reply) => {});
@LanciWeb
LanciWeb / noteRoutes.js
Created October 15, 2020 17:58
V2 routes for the Fastify + React Admin project on Medium
const notesController = require('../controllers/notesController');
module.exports = (app) => {
//# create a note
app.post('/api/notes', notesController.create);
//#get the list of notes
app.get('/api/notes', notesController.fetch);
//#get a single note
@LanciWeb
LanciWeb / notesConroller.js
Last active October 15, 2020 17:57
empty controller for the Fastify + React Admin project on Medium
const Note = require('../models/note');
module.exports = {
//# create a note
create: async (request, reply) => {},
//#get the list of notes
fetch: async (request, reply) => {},
//#get a single note
@LanciWeb
LanciWeb / notesConroller.js
Created October 15, 2020 17:51
Controller delete function for the Fastify + React Admin project on Medium
//#delete a note
delete: async (request, reply) => {
try {
const noteId = request.params.id;
const noteToDelete = await Note.findById(noteId);
await Note.findByIdAndDelete(noteId);
reply.code(200).send({ data: noteToDelete });
} catch (e) {
reply.code(500).send(e);
}
@LanciWeb
LanciWeb / notesConroller.js
Created October 15, 2020 17:50
Controller update function for the Fastify + React Admin project on Medium
//#update a note
update: async (request, reply) => {
try {
const noteId = request.params.id;
const updates = request.body;
await Note.findByIdAndUpdate(noteId, updates);
const noteToUpdate = await Note.findById(noteId);
reply.code(200).send({ data: noteToUpdate });
} catch (e) {
reply.code(500).send(e);