improvements to jobs
This commit is contained in:
parent
ebbd1175b1
commit
7df375e752
|
@ -236,9 +236,6 @@ export default {
|
||||||
|
|
||||||
switch (subFull?.rankingType) {
|
switch (subFull?.rankingType) {
|
||||||
case 'AUCTION':
|
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(`
|
items = await models.$queryRaw(`
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM (
|
FROM (
|
||||||
|
|
|
@ -98,7 +98,7 @@ export default {
|
||||||
FROM "Item"
|
FROM "Item"
|
||||||
WHERE "Item"."userId" = $1
|
WHERE "Item"."userId" = $1
|
||||||
AND "maxBid" IS NOT NULL
|
AND "maxBid" IS NOT NULL
|
||||||
AND "statusUpdatedAt" <= $2
|
AND "statusUpdatedAt" <= $2 AND "statusUpdatedAt" <> created_at
|
||||||
ORDER BY "sortTime" DESC
|
ORDER BY "sortTime" DESC
|
||||||
LIMIT ${LIMIT}+$3)`
|
LIMIT ${LIMIT}+$3)`
|
||||||
)
|
)
|
||||||
|
|
|
@ -212,7 +212,7 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (job) {
|
if (job && job.statusUpdatedAt > job.createdAt) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
import Toc from './table-of-contents'
|
import Toc from './table-of-contents'
|
||||||
import { Button, Image } from 'react-bootstrap'
|
import { Badge, Button, Image } from 'react-bootstrap'
|
||||||
import { SearchTitle } from './item'
|
import { SearchTitle } from './item'
|
||||||
import styles from './item.module.css'
|
import styles from './item.module.css'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
@ -59,16 +59,18 @@ export default function ItemJob ({ item, toc, rank, children }) {
|
||||||
</Link>
|
</Link>
|
||||||
</span>
|
</span>
|
||||||
{item.mine &&
|
{item.mine &&
|
||||||
<>
|
(
|
||||||
<wbr />
|
<>
|
||||||
<span> \ </span>
|
<wbr />
|
||||||
<Link href={`/items/${item.id}/edit`} passHref>
|
<span> \ </span>
|
||||||
<a className='text-reset'>
|
<Link href={`/items/${item.id}/edit`} passHref>
|
||||||
edit
|
<a className='text-reset'>
|
||||||
</a>
|
edit
|
||||||
</Link>
|
</a>
|
||||||
{item.status !== 'ACTIVE' && <span className='ml-1 font-weight-bold text-boost'> {item.status}</span>}
|
</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>
|
||||||
</div>
|
</div>
|
||||||
{toc && <Toc text={item.text} />}
|
{toc && <Toc text={item.text} />}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import Avatar from './avatar'
|
||||||
import BootstrapForm from 'react-bootstrap/Form'
|
import BootstrapForm from 'react-bootstrap/Form'
|
||||||
import Alert from 'react-bootstrap/Alert'
|
import Alert from 'react-bootstrap/Alert'
|
||||||
import { useMe } from './me'
|
import { useMe } from './me'
|
||||||
|
import ActionTooltip from './action-tooltip'
|
||||||
|
|
||||||
Yup.addMethod(Yup.string, 'or', function (schemas, msg) {
|
Yup.addMethod(Yup.string, 'or', function (schemas, msg) {
|
||||||
return this.test({
|
return this.test({
|
||||||
|
@ -183,7 +184,11 @@ export default function JobForm ({ item, sub }) {
|
||||||
/>
|
/>
|
||||||
<PromoteJob item={item} sub={sub} storageKeyPrefix={storageKeyPrefix} />
|
<PromoteJob item={item} sub={sub} storageKeyPrefix={storageKeyPrefix} />
|
||||||
{item && <StatusControl item={item} />}
|
{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>
|
</Form>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
@ -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;
|
||||||
|
$$;
|
Loading…
Reference in New Issue