Skip to content

Instantly share code, notes, and snippets.

Avatar

Abhi Aiyer abhiaiyer91

  • Workpop
  • Los Angeles
View GitHub Profile
View multi-table.js
// Print out the grade-school multiplication table up to 12x12
function multiplicationTable(maxValue) {
for (var i = 1; i <= maxValue; i++) {
let line
for (var j = 1; j <= maxValue; j++) {
line = line + ` ${j * i}`;
}
console.log(line)
}
View post2.ts
/** rest of code above **/
server.get("/post/:id", async (req, res) => {
const postId = req.params.id;
// Use the post API from prisma client
try {
const post = await prisma.post({
id: postId
});
const author = await prisma
View postsdrafts.ts
/** rest of code above **/
server.get("/posts", async (_req, res) => {
// Use the posts API from prisma client
try {
const posts = await prisma.posts({
where: {
published: true
}
});
View post.ts
/** rest of code above **/
server.get("/post/:id", async (req, res) => {
const postId = req.params.id;
// Use the post API from prisma client
try {
const post = await prisma.post({
id: postId
});
View publishpost.ts
/** rest of code above **/
server.post("/post/publish/:id", async (req, res) => {
const postId = req.params.id;
// Use the updatePost API from prisma client
try {
const publishedPost = await prisma.updatePost({
where: {
id: postId
},
View createpost.ts
/** rest of code above **/
server.post("/create/draft", async (req, res) => {
const { title, authorId } = req.body;
// Use the createPost API from prisma client
try {
const draftPost = await prisma.createPost({
title,
author: {
connect: {
View user.ts
/** rest of code above **/
server.get("/user/:id", async (req, res) => {
const userId = req.params.id;
// Use the user API from prisma client
try {
const user = await prisma.user({
id: userId
});
View createuser.ts
import * as express from "express";
import * as bodyParser from "body-parser";
import { prisma } from "./generated/prisma-client";
const server = express();
server.use(bodyParser.json());
// User APIs
server.post("/create/user", async (req, res) => {
View index.ts
import * as express from "express";
import * as bodyParser from "body-parser";
const server = express();
server.use(bodyParser.json());
// User APIs
server.post("/create/user", () => {});
server.get("/user/:id", () => {});
View tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"outDir": "dist",
"strict": true,
"lib": ["esnext", "dom"]
}
}