Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/api-main/src/posts/dislike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const statementAddDislikeToPost = getDatabase()
export async function Dislike(body: typeof Posts.DislikeBody.static) {
try {
await statement.execute({
post_hash: body.post_hash,
hash: body.hash,
author: body.from,
post_hash: body.post_hash.toLowerCase(),
hash: body.hash.toLowerCase(),
author: body.from.toLowerCase(),
quantity: body.quantity,
timestamp: new Date(body.timestamp),
});
Expand Down
6 changes: 3 additions & 3 deletions packages/api-main/src/posts/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const statementAddFlagToPost = getDatabase()
export async function Flag(body: typeof Posts.FlagBody.static) {
try {
await statement.execute({
post_hash: body.post_hash,
hash: body.hash,
author: body.from,
post_hash: body.post_hash.toLowerCase(),
hash: body.hash.toLowerCase(),
author: body.from.toLowerCase(),
quantity: body.quantity,
timestamp: new Date(body.timestamp),
});
Expand Down
6 changes: 3 additions & 3 deletions packages/api-main/src/posts/follow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const statementAddFollower = getDatabase()
export async function Follow(body: typeof Posts.FollowBody.static) {
try {
await statementAddFollower.execute({
follower: body.from,
following: body.address,
hash: body.hash,
follower: body.from.toLowerCase(),
following: body.address.toLowerCase(),
hash: body.hash.toLowerCase(),
timestamp: new Date(body.timestamp),
});

Expand Down
6 changes: 3 additions & 3 deletions packages/api-main/src/posts/like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const statementAddLikeToPost = getDatabase()
export async function Like(body: typeof Posts.LikeBody.static) {
try {
await statement.execute({
post_hash: body.post_hash,
hash: body.hash,
author: body.from,
post_hash: body.post_hash.toLowerCase(),
hash: body.hash.toLowerCase(),
author: body.from.toLowerCase(),
quantity: body.quantity,
timestamp: new Date(body.timestamp),
});
Expand Down
40 changes: 20 additions & 20 deletions packages/api-main/src/posts/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const statementAuditRemovePost = getDatabase()
})
.prepare('stmnt_audit_remove_post');

export async function ModRemovePost(body: typeof Posts.ModRemovePostBody.static, store) {
export async function ModRemovePost(body: typeof Posts.ModRemovePostBody.static, store: { userAddress: string }) {
try {
const [mod] = await getDatabase()
.select()
Expand All @@ -35,18 +35,18 @@ export async function ModRemovePost(body: typeof Posts.ModRemovePostBody.static,
.update(FeedTable)
.set({
removed_at: new Date(body.timestamp),
removed_hash: body.hash,
removed_by: mod.address,
removed_hash: body.hash.toLowerCase(),
removed_by: mod.address.toLowerCase(),
})
.where(eq(FeedTable.hash, body.post_hash))
.returning();

await statement.execute();

await statementAuditRemovePost.execute({
post_hash: body.post_hash,
hash: body.hash,
created_by: mod.address,
post_hash: body.post_hash.toLowerCase(),
hash: body.hash.toLowerCase(),
created_by: mod.address.toLowerCase(),
created_at: new Date(body.timestamp),
reason: body.reason,
});
Expand All @@ -70,7 +70,7 @@ const statementAuditRestorePost = getDatabase()
})
.prepare('stmnt_audit_restore_post');

export async function ModRestorePost(body: typeof Posts.ModRemovePostBody.static, store) {
export async function ModRestorePost(body: typeof Posts.ModRemovePostBody.static, store: { userAddress: string }) {
try {
const [mod] = await getDatabase()
.select()
Expand Down Expand Up @@ -112,9 +112,9 @@ export async function ModRestorePost(body: typeof Posts.ModRemovePostBody.static
await statement.execute();

await statementAuditRestorePost.execute({
post_hash: body.post_hash,
hash: body.hash,
restored_by: mod.address,
post_hash: body.post_hash.toLowerCase(),
hash: body.hash.toLowerCase(),
restored_by: mod.address.toLowerCase(),
restored_at: new Date(body.timestamp),
reason: body.reason,
});
Expand All @@ -138,7 +138,7 @@ const statementAuditBanUser = getDatabase()
})
.prepare('stmnt_audit_ban_user');

export async function ModBan(body: typeof Posts.ModBanBody.static, store) {
export async function ModBan(body: typeof Posts.ModBanBody.static, store: { userAddress: string }) {
try {
const [mod] = await getDatabase()
.select()
Expand All @@ -153,18 +153,18 @@ export async function ModBan(body: typeof Posts.ModBanBody.static, store) {
.update(FeedTable)
.set({
removed_at: new Date(body.timestamp),
removed_hash: body.hash,
removed_by: mod.address,
removed_hash: body.hash.toLowerCase(),
removed_by: mod.address.toLowerCase(),
})
.where(and(eq(FeedTable.author, body.user_address), isNull(FeedTable.removed_at)))
.returning();

await statement.execute();

await statementAuditBanUser.execute({
user_address: body.user_address,
hash: body.hash,
created_by: mod.address,
user_address: body.user_address.toLowerCase(),
hash: body.hash.toLowerCase(),
created_by: mod.address.toLowerCase(),
created_at: new Date(body.timestamp),
reason: body.reason,
});
Expand All @@ -188,7 +188,7 @@ const statementAuditUnbanUser = getDatabase()
})
.prepare('stmnt_audit_unban_user');

export async function ModUnban(body: typeof Posts.ModBanBody.static, store) {
export async function ModUnban(body: typeof Posts.ModBanBody.static, store: { userAddress: string }) {
try {
const [mod] = await getDatabase()
.select()
Expand Down Expand Up @@ -221,9 +221,9 @@ export async function ModUnban(body: typeof Posts.ModBanBody.static, store) {
await statement.execute();

await statementAuditUnbanUser.execute({
user_address: body.user_address,
hash: body.hash,
restored_by: mod.address,
user_address: body.user_address.toLowerCase(),
hash: body.hash.toLowerCase(),
restored_by: mod.address.toLowerCase(),
restored_at: new Date(body.timestamp),
reason: body.reason,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/api-main/src/posts/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const statement = getDatabase()
export async function Post(body: typeof Posts.PostBody.static) {
try {
await statement.execute({
hash: body.hash,
hash: body.hash.toLowerCase(),
timestamp: new Date(body.timestamp),
author: body.from,
author: body.from.toLowerCase(),
message: body.msg,
quantity: body.quantity,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/api-main/src/posts/postRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export async function PostRemove(body: typeof Posts.PostRemoveBody.static) {
.update(FeedTable)
.set({
removed_at: new Date(body.timestamp),
removed_hash: body.hash,
removed_by: body.from,
removed_hash: body.hash.toLowerCase(),
removed_by: body.from.toLowerCase(),
})
.where(eq(FeedTable.hash, body.post_hash))
.returning();
Expand Down
6 changes: 3 additions & 3 deletions packages/api-main/src/posts/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const statementAddReplyCount = getDatabase()
export async function Reply(body: typeof Posts.ReplyBody.static) {
try {
await statement.execute({
author: body.from,
hash: body.hash,
author: body.from.toLowerCase(),
hash: body.hash.toLowerCase(),
message: body.msg,
post_hash: body.post_hash,
post_hash: body.post_hash.toLowerCase(),
quantity: body.quantity,
timestamp: new Date(body.timestamp),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/api-main/src/posts/unfollow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const statementRemoveFollowing = getDatabase()

export async function Unfollow(body: typeof Posts.UnfollowBody.static) {
try {
await statementRemoveFollowing.execute({ follower: body.from, following: body.address, removed_at: new Date(body.timestamp) });
await statementRemoveFollowing.execute({ follower: body.from.toLowerCase(), following: body.address.toLowerCase(), removed_at: new Date(body.timestamp) });

return { status: 200 };
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api-main/tests/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function post<T = { status: number }>(

const jsonData = (await response.json()) as { status: number };
if (jsonData.status && jsonData.status !== 200) {
return jsonData;
return jsonData as T;
}

return jsonData as T;
Expand Down
2 changes: 1 addition & 1 deletion packages/api-main/tests/v1.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../src/index';

import type * as Posts from '../src/posts/index';
import type { Posts } from '@atomone/dither-api-types';

import { sql } from 'drizzle-orm';
import { assert, describe, it } from 'vitest';
Expand Down