Add: Success object
This commit is contained in:
parent
4975c0b34f
commit
5d2c9c5f9a
@ -68,7 +68,7 @@ export async function getCategories(category_ids = undefined) {
|
||||
|
||||
/**
|
||||
* @param {number} category_id
|
||||
* @returns {Promise<Category | import('$types/error').Error>}
|
||||
* @returns {Promise<Category | import('$types/status').Error>}
|
||||
*/
|
||||
export async function getCategoryCached(category_id) {
|
||||
const categories = await getCategoriesCached([category_id]);
|
||||
|
||||
@ -96,7 +96,7 @@ export async function getPosts(opts = {}) {
|
||||
* @param {{
|
||||
* withMetrics?: boolean
|
||||
* }} opts
|
||||
* @returns {Promise<Post | import('$types/error').Error>}
|
||||
* @returns {Promise<Post | import('$types/status').Error>}
|
||||
*/
|
||||
export async function getPost(post_id, opts = {}) {
|
||||
const {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { createCache } from '$lib/cache.server';
|
||||
import { genSalt } from 'bcrypt';
|
||||
import { cacheUpdater, cachedMethod, refExtendCachedMethod } from './root';
|
||||
import { sql } from '$lib/db.server';
|
||||
import { argon2id, hash, verify } from 'argon2';
|
||||
import { PostgresError } from 'postgres';
|
||||
|
||||
const cache = createCache();
|
||||
|
||||
@ -32,7 +34,6 @@ function parseUserFromRow(row) {
|
||||
const updateUserCache = cacheUpdater(cache);
|
||||
|
||||
/**
|
||||
* @param {import('postgres').Sql} sql
|
||||
* @param {number[]} user_ids
|
||||
* @returns {Promise<Result<User>>}
|
||||
*/
|
||||
@ -41,11 +42,10 @@ export const getUsersCached = cachedMethod(cache, getUsers);
|
||||
export const getUsersCachedByRef = refExtendCachedMethod(getUsersCached);
|
||||
|
||||
/**
|
||||
* @param {import('postgres').Sql} sql
|
||||
* @param {number[]} user_ids
|
||||
* @returns {Promise<Result<User>>}
|
||||
*/
|
||||
export async function getUsers(sql, user_ids) {
|
||||
export async function getUsers(user_ids) {
|
||||
if (user_ids.length == 0) return new Map();
|
||||
|
||||
const query = sql`
|
||||
@ -68,12 +68,11 @@ export async function getUsers(sql, user_ids) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('postgres').Sql} sql
|
||||
* @param {number} user_id
|
||||
* @returns {Promise<User | import('$types/error').Error>}
|
||||
* @returns {Promise<User | import('$types/status').Error>}
|
||||
*/
|
||||
export async function getUser(sql, user_id) {
|
||||
const users = await getUsers(sql, [user_id]);
|
||||
export async function getUser(user_id) {
|
||||
const users = await getUsers([user_id]);
|
||||
|
||||
return users.get(user_id) || {
|
||||
error: true,
|
||||
@ -82,10 +81,9 @@ export async function getUser(sql, user_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('postgres').Sql} sql
|
||||
* @param {string} username
|
||||
* @param {string} password
|
||||
* @returns {Promise<string | import('$types/error').Error>}
|
||||
* @returns {Promise<import('$types/status').Success | import('$types/status').Error>}
|
||||
*/
|
||||
export async function registerUser(sql, username, password) {
|
||||
// const users = await getUsers(sql, [user_id]);
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
export type Error = {
|
||||
error: boolean,
|
||||
msg: string
|
||||
};
|
||||
8
src/types/status.ts
Normal file
8
src/types/status.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export type Error = {
|
||||
error: boolean,
|
||||
msg: string,
|
||||
};
|
||||
|
||||
export type Success = {
|
||||
success: boolean,
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user