blob: 800f0b9e6300bcc4019941ad3b7f8959949235f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import { Meta } from '../models/entities/meta';
import { getConnection } from 'typeorm';
export default async function(): Promise<Meta> {
return await getConnection().transaction(async transactionalEntityManager => {
// バグでレコードが複数出来てしまっている可能性があるので新しいIDを優先する
const meta = await transactionalEntityManager.findOne(Meta, {
order: {
id: 'DESC'
}
});
if (meta) {
return meta;
} else {
return await transactionalEntityManager.save(Meta, {
id: 'x'
}) as Meta;
}
});
}
|