mirror of
https://github.com/logto-io/logto.git
synced 2025-03-24 22:41:28 -05:00
* test(core): add ut for queires add ut for queries * test(core): add user query ut add user query ut * fix(core): remove test code remove console log
35 lines
1,000 B
TypeScript
35 lines
1,000 B
TypeScript
import { ResourceScope, CreateResourceScope, ResourceScopes } from '@logto/schemas';
|
|
import { sql } from 'slonik';
|
|
|
|
import { buildInsertInto } from '@/database/insert-into';
|
|
import pool from '@/database/pool';
|
|
import { convertToIdentifiers } from '@/database/utils';
|
|
import { DeletionError } from '@/errors/SlonikError';
|
|
|
|
const { table, fields } = convertToIdentifiers(ResourceScopes);
|
|
|
|
export const findAllScopesWithResourceId = async (resourceId: string) =>
|
|
pool.any<ResourceScope>(sql`
|
|
select ${sql.join(Object.values(fields), sql`, `)}
|
|
from ${table}
|
|
where ${fields.resourceId}=${resourceId}
|
|
`);
|
|
|
|
export const insertScope = buildInsertInto<CreateResourceScope, ResourceScope>(
|
|
pool,
|
|
ResourceScopes,
|
|
{
|
|
returning: true,
|
|
}
|
|
);
|
|
|
|
export const deleteScopeById = async (id: string) => {
|
|
const { rowCount } = await pool.query(sql`
|
|
delete from ${table}
|
|
where ${fields.id}=${id}
|
|
`);
|
|
|
|
if (rowCount < 1) {
|
|
throw new DeletionError(ResourceScopes.table, id);
|
|
}
|
|
};
|