rename post to pool

This commit is contained in:
Michael Fatemi 2021-04-10 11:44:43 -04:00
parent b09bb33b95
commit dfc06182a4
3 changed files with 13 additions and 13 deletions

View File

@ -1,5 +1,5 @@
import { Router } from 'express';
import { getGroupByID, getPostByID, getUserByID } from './data';
import { getGroupByID, getPoolByID, getUserByID } from './data';
export const router = Router();
@ -18,16 +18,16 @@ router.get('/user', (req, res) => {
}
});
router.get('/post', (req, res) => {
if (typeof req.query.postID != 'string') {
router.get('/pool', (req, res) => {
if (typeof req.query.poolID != 'string') {
return;
}
let postID = req.query.postID;
let post = getPostByID(postID);
let poolID = req.query.poolID;
let pool = getPoolByID(poolID);
if (post) {
res.json({ status: 'success', data: post });
if (pool) {
res.json({ status: 'success', data: pool });
} else {
res.json({ status: 'error', error: 'not_found' });
}

View File

@ -15,9 +15,9 @@ export const users: Record<string, Carpool.User> = {
export const groups: Record<string, Carpool.Group> = {};
/**
* Records posts by id
* Records pools by id
*/
export const posts: Record<string, Carpool.Post> = {};
export const pools: Record<string, Carpool.Pool> = {};
/**
*
@ -42,7 +42,7 @@ export function getGroupsWithUser(userID: string) {
*/
export function getPostsByUser(userID: string) {
let postIDs = [];
for (let post of Object.values(posts)) {
for (let post of Object.values(pools)) {
if (post.author_id == userID) {
postIDs.push(post.id);
}
@ -55,8 +55,8 @@ export function getUserByID(userID: string): Carpool.User | undefined {
return users[userID];
}
export function getPostByID(postID: string): Carpool.Post | undefined {
return posts[postID];
export function getPoolByID(poolID: string): Carpool.Pool | undefined {
return pools[poolID];
}
export function getGroupByID(groupID: string): Carpool.Group | undefined {

View File

@ -18,7 +18,7 @@ namespace Carpool {
export type Status = 'pending' | 'cancelled' | 'completed' | 'interrupted';
export interface Post {
export interface Pool {
id: string;
title: string;
description: string;