improvements to jobs

This commit is contained in:
keyan 2022-11-29 11:28:57 -06:00
parent ebbd1175b1
commit 7df375e752
6 changed files with 63 additions and 17 deletions

View File

@ -236,9 +236,6 @@ export default {
switch (subFull?.rankingType) {
case 'AUCTION':
// it might be sufficient to sort by the floor(maxBid / 1000) desc, created_at desc
// we pull from their wallet
// TODO: need to filter out by payment status
items = await models.$queryRaw(`
SELECT *
FROM (

View File

@ -98,7 +98,7 @@ export default {
FROM "Item"
WHERE "Item"."userId" = $1
AND "maxBid" IS NOT NULL
AND "statusUpdatedAt" <= $2
AND "statusUpdatedAt" <= $2 AND "statusUpdatedAt" <> created_at
ORDER BY "sortTime" DESC
LIMIT ${LIMIT}+$3)`
)

View File

@ -212,7 +212,7 @@ export default {
}
}
})
if (job) {
if (job && job.statusUpdatedAt > job.createdAt) {
return true
}

View File

@ -1,6 +1,6 @@
import * as Yup from 'yup'
import Toc from './table-of-contents'
import { Button, Image } from 'react-bootstrap'
import { Badge, Button, Image } from 'react-bootstrap'
import { SearchTitle } from './item'
import styles from './item.module.css'
import Link from 'next/link'
@ -59,16 +59,18 @@ export default function ItemJob ({ item, toc, rank, children }) {
</Link>
</span>
{item.mine &&
<>
<wbr />
<span> \ </span>
<Link href={`/items/${item.id}/edit`} passHref>
<a className='text-reset'>
edit
</a>
</Link>
{item.status !== 'ACTIVE' && <span className='ml-1 font-weight-bold text-boost'> {item.status}</span>}
</>}
(
<>
<wbr />
<span> \ </span>
<Link href={`/items/${item.id}/edit`} passHref>
<a className='text-reset'>
edit
</a>
</Link>
{item.status !== 'ACTIVE' && <span className='ml-1 font-weight-bold text-boost'> {item.status}</span>}
</>)}
{item.maxBid > 0 && item.status === 'ACTIVE' && <Badge className={`${styles.newComment} ml-1`}>PROMOTED</Badge>}
</div>
</div>
{toc && <Toc text={item.text} />}

View File

@ -14,6 +14,7 @@ import Avatar from './avatar'
import BootstrapForm from 'react-bootstrap/Form'
import Alert from 'react-bootstrap/Alert'
import { useMe } from './me'
import ActionTooltip from './action-tooltip'
Yup.addMethod(Yup.string, 'or', function (schemas, msg) {
return this.test({
@ -183,7 +184,11 @@ export default function JobForm ({ item, sub }) {
/>
<PromoteJob item={item} sub={sub} storageKeyPrefix={storageKeyPrefix} />
{item && <StatusControl item={item} />}
<SubmitButton variant='secondary' className='mt-3'>{item ? 'save' : 'post'}</SubmitButton>
<div className='d-flex align-items-center mt-3'>
<ActionTooltip overlayText='1000 sats'>
<SubmitButton variant='secondary'>{item ? 'save' : <>post <small> 1000 sats</small></>}</SubmitButton>
</ActionTooltip>
</div>
</Form>
</>
)

View File

@ -0,0 +1,42 @@
CREATE OR REPLACE FUNCTION create_job(
title TEXT, url TEXT, text TEXT, user_id INTEGER, job_bid INTEGER, job_company TEXT,
job_location TEXT, job_remote BOOLEAN, job_upload_id INTEGER)
RETURNS "Item"
LANGUAGE plpgsql
AS $$
DECLARE
item "Item";
user_msats BIGINT;
cost_msats BIGINT;
BEGIN
PERFORM ASSERT_SERIALIZED();
-- 1000 sats to create a job
cost_msats := 1000000;
SELECT msats
INTO user_msats
FROM users
WHERE id = user_id;
IF cost_msats > user_msats THEN
RAISE EXCEPTION 'SN_INSUFFICIENT_FUNDS';
END IF;
-- create item
INSERT INTO "Item" (title, url, text, "userId", "maxBid", company, location, remote, "uploadId", "subName", "statusUpdatedAt", created_at, updated_at)
VALUES (title, url, text, user_id, job_bid, job_company, job_location, job_remote, job_upload_id, 'jobs', now_utc(), now_utc(), now_utc()) RETURNING * INTO item;
-- deduct from user
UPDATE users SET msats = msats - cost_msats WHERE id = user_id;
-- record fee
INSERT INTO "ItemAct" (msats, "itemId", "userId", act, created_at, updated_at)
VALUES (cost_msats, item.id, user_id, 'FEE', now_utc(), now_utc());
-- run_auction
EXECUTE run_auction(item.id);
RETURN item;
END;
$$;